Java和MySQL - 列数与第1行的值计数不匹配

时间:2022-07-23 20:08:14

I've got an issue and would be nice to receive feedback from you. While updating the data of my table in MySQL, the following message appears:

我有一个问题,很高兴收到你的反馈。在MySQL中更新我的表的数据时,会出现以下消息:

Column count doesn't match value count at row 1

列数与第1行的值计数不匹配

The table is:

该表是:

IdUsuari INT NOT NULL AUTO_INCREMENT, Nickname VARCHAR(50) NOT NULL, DataRegistre DATE NOT NULL, DataDarrerAcces DATE NOT NULL, NumLlistes INT NOT NULL DEFAULT 0, Password VARCHAR(10) NOT NULL, Admin INT NOT NULL, PRIMARY KEY (IdUsuari)

IdUsuari INT NOT NULL AUTO_INCREMENT,Nickname VARCHAR(50)NOT NULL,DataRegistre DATE NOT NULL,DataDarrerAcces DATE NOT NULL,NumLlistes INT NOT NULL DEFAULT 0,Password VARCHAR(10)NOT NULL,Admin INT NOT NULL,PRIMARY KEY(IdUsuari)

And the code:

和代码:

public static void RegistreUsuari(int port, String ip, String nickname, String password) throws SQLException{ /*Creem un usuari*/

        java.util.Date dt = new java.util.Date(); 



        Connection conn = getConnection(port,ip);
        Statement st = null;
        st = conn.createStatement();



        String query = new String();
        /*Data*/

        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        String currentTime = sdf.format(dt);
        query = "INSERT INTO usuari(Nickname, Password, DataRegistre, DataDarrerAcces, NumLlistes, Admin) VALUES('" + nickname +"','"+password+"','"+currentTime+"','"+currentTime+"',0)";
        st.executeUpdate(query); }

And

Database.RegistreUsuari(port, ip, "Elder", "hola");

Thank you in advance!

先感谢您!

1 个解决方案

#1


You are trying to insert 5 values to a table with 6 columns. You don't specify a value for NumLlistes.

您正尝试将5个值插入到包含6列的表中。您没有为NumLlistes指定值。

If you wish the default value to be used, don't specify the NumLlistes column in the insert statement :

如果希望使用默认值,请不要在insert语句中指定NumLlistes列:

query = "INSERT INTO usuari(Nickname, Password, DataRegistre, DataDarrerAcces, Admin) VALUES('" + nickname +"','"+password+"','"+currentTime+"','"+currentTime+"',0)";

#1


You are trying to insert 5 values to a table with 6 columns. You don't specify a value for NumLlistes.

您正尝试将5个值插入到包含6列的表中。您没有为NumLlistes指定值。

If you wish the default value to be used, don't specify the NumLlistes column in the insert statement :

如果希望使用默认值,请不要在insert语句中指定NumLlistes列:

query = "INSERT INTO usuari(Nickname, Password, DataRegistre, DataDarrerAcces, Admin) VALUES('" + nickname +"','"+password+"','"+currentTime+"','"+currentTime+"',0)";