我的代码中有这个:
String query
= "INSERT INTO usermail (FirstName, LastName, Town, Country, Email) "
+ "VALUES (?, ?, ?, ? ,?)";
Run Code Online (Sandbox Code Playgroud)
我的表如下:
UserID – AutoNumber (Primary Key)
FirstName – varchar(15)
astName – varchar (15)
Town – varchar(15)
Country – varchar(15)
Email – varchar(20)
Run Code Online (Sandbox Code Playgroud)
问题是,当我第一次填写表单时,所有值都被添加到数据库中,但如果我第二次尝试这样做,它们将不会被添加。如果我删除 UserID 表,一切正常。这就是我创建 UserID 的方式(图片取自 -此处)

我不确定如何使其与 UserID 一起使用。我无法在其中输入任何内容,因为我的表单中没有这样的字段。
这是我从 stackTrace 得到的
Info: visiting unvisited references
Info: visiting unvisited references
Info: Loading application [MailRegistration] at [/MailRegistration]
Info: MailRegistration was successfully deployed in 293 milliseconds.
Severe: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: …Run Code Online (Sandbox Code Playgroud) 我遇到了一个错误,java.sql.SQLException:
Column count doesn't match value count at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
Run Code Online (Sandbox Code Playgroud)
这是非常令人沮丧的,因为我一直在修改代码,比如将arg更改为所有字符串,但错误仍然出现.
public void readDataBase(int val, String d1, String d2, String d3, String d4 ) throws Exception {
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/MAXdb?"+ "user=root&password=");
// Statements allow to issue SQL queries to the …Run Code Online (Sandbox Code Playgroud)