我试图在表中插入数据,但它显示以下错误:
java.sql.SQLException:列计数与第 1 行的值计数不匹配
我已经搜索了这个错误并尝试了所有解决方案,但仍然无法使其工作。这是我的代码:
类.html
<html>
<head>
<title>Class</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="post" action="class.jsp">
<center>
<table border="1" width="30%" cellpadding="5">
<thead>
<tr>
<th colspan="2">Enter Information Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>Class Name</td>
<td><input type="text" name="name" value="" /></td>
</tr>
<tr>
<td>Class Strength</td>
<td><input type="text" name="strength" value="" /></td>
</tr>
<tr>
<td>Room</td>
<td>
<input type="text" name="room" value="">
</td>
</tr>
<tr>
<td>Section</td>
<td><input type="text" name="section" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
类.jsp
<%@ page import ="java.sql.*" import= "java.sql.Connection"
%>
<%
String cname = request.getParameter("name");
String cstrength = request.getParameter("strength");
String croom = request.getParameter("room");
String csection = request.getParameter("section");
//String available = request.getParameter("bavailable");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web",
"root", "");
Statement st = con.createStatement();
//ResultSet rs;
int i = st.executeUpdate("insert into class(name, strength ,room, section) values ('" + cname + "','" + cstrength + "','" + croom + "','" + csection + "', CURDATE());");
if (i > 0) {
//session.setAttribute("userid", user);
response.sendRedirect("wel.jsp");
// out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
} else {
response.sendRedirect("index.jsp");
}
%>
这是您正在运行的查询:
insert into class(name, strength ,room, section) values ('" + cname + "','" + cstrength + "','" + croom + "','" + csection + "', CURDATE());")
您提到要传递 4 个列值(class(name, strength ,room, section)
),但是你传入了 5 个值(CURDATE() 的额外值)
在表中添加该新列并更新查询以也包含该列(即(class(name, strength ,room, section, curdate)
)) 或删除 CURDATE()。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)