gpt4 book ai didi

java - 如何解决 java.sql.SQLException : Column count doesn't match value count at row 1 why?

转载 作者:行者123 更新时间:2023-12-01 06:01:44 25 4
gpt4 key购买 nike

不明白为什么会出现错误

java.sql.SQLException: Column count doesn't match value count at row 1

我的代码是

<%@ page import="java.sql.*" %>
<%
String ime = request.getParameter ("ime");
String priimek = request.getParameter ("priimek");
String spol = request.getParameter ("spol");
String email= request.getParameter ("email");
String gsm = request.getParameter ("gsm");
String datumr = request.getParameter ("datumr");
String subject = request.getParameter ("subject");
String q1 = request.getParameter ("q1");
String q2 = request.getParameter ("q2");
String q3 = request.getParameter ("q3");
String q4 = request.getParameter ("q4");
String q5 = request.getParameter ("q5");
String q6 = request.getParameter ("q6");
String q7 = request.getParameter ("q7");
String q8 = request.getParameter ("q8");
String q9 = request.getParameter ("q9");
String q10 = request.getParameter ("q10");

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/zora", "zora",
"zora0101");
stmt = con.createStatement();
stmt.executeUpdate ("INSERT INTO stranki (ime, priimek, spol, email, gsm,
datumr, subject, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10) VALUES
('"+ime+"', '"+priimek+"', '"+spol+"', '"+email+"','"+gsm+"',
'"+datumr+"', '"+subject+"', '"+q1+"', '"+q2+"', '"+q3+"', '"+q4+"',
'"+q5+"', '"+q6+"' '"+q7+"', '"+q8+"', '"+q9+"', '"+q10+"')");
} catch(Exception e) %>

我做错了什么?

最佳答案

有时会发生这种情况,不用担心。您的代码中缺少逗号:

VALUES 

('"+ime+"', '"+priimek+"', '"+spol+"', '"+email+"','"+gsm+"',
'"+datumr+"', '"+subject+"', '"+q1+"', '"+q2+"', '"+q3+"', '"+q4+"',
'"+q5+"', '"+q6+"'**comma missing here** '"+q7+"', '"+q8+"', '"+q9+"', '"+q10+"')");
}

更正的代码:

VALUES 
('"+ime+"', '"+priimek+"', '"+spol+"', '"+email+"','"+gsm+"',
'"+datumr+"', '"+subject+"', '"+q1+"', '"+q2+"', '"+q3+"', '"+q4+"',
'"+q5+"', '"+q6+"', '"+q7+"', '"+q8+"', '"+q9+"', '"+q10+"')");
}

希望它能解决您的问题。

关于java - 如何解决 java.sql.SQLException : Column count doesn't match value count at row 1 why?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56709347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com