2

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:

Column count doesn't match value count at row 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)

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!

5
  • Apart from the fact that storing passwords in plaintext is a bad idea in general, you should really look into PreparedStatement for any sort of user input! Commented May 8, 2015 at 7:29
  • I'm voting to close this question as off-topic because You have 6 columns 6 values in your query and that's the answer. Commented May 8, 2015 at 7:29
  • @Hanky웃Panky I don't see how that makes it off-topic, it just means that that'S where the problem lies as you have already stated in your answer Commented May 8, 2015 at 7:31
  • You should be using a PreapredStatement, see Using Prepared Statements for more details Commented May 8, 2015 at 7:33
  • @Dragondraikk in my (possibly wrong) opinion, thats just a typo not a problem; hence the light hearet close-vote. Otherwise if you search SO for this very error message that this question contains there are 408 duplicate questions to be exact which is in itself a big enough close reason. Commented May 8, 2015 at 7:51

1 Answer 1

6

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

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

query = "INSERT INTO usuari(Nickname, Password, DataRegistre, DataDarrerAcces, Admin) VALUES('" + nickname +"','"+password+"','"+currentTime+"','"+currentTime+"',0)";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.