で値の数と一致していない私は、テーブル内のデータを挿入しようとしているが、それは次のようなエラーが表示されます。ます。java.sql.SQLException:列数が行1エラー
java.sql.SQLException: Column count doesn't match value count at row 1
私が検索しましたこのエラーと私はすべてのソリューションを試しましたが、まだそれを動作させることはできません。
class.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>
class.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");
}
%>
[SQLインジェクション](https://en.wikipedia.org/wiki/SQL_injection)を防止するには、プリペアドステートメントを使用する必要があります。 – GriffeyDog
BTW SQL Serverエラーに関連するHTMLコードはどのようになっていますか? –
パラメータ付きプリペアドステートメントの使い方を学んでください。 **クエリ文字列に値を連結しないでください**。 SQLインジェクションに脆弱です! –