0
String sql = "INSERT INTO user (userid, username, password, lastname, firstname, "
            + "middlename, birthdate, gender, address, email, contact, "
            + "marital_status, religion) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
    try {
        pst = conn.prepareStatement(sql);

        pst.setString(1, username);
        pst.setString(2, password.toString()); //chartype
        pst.setString(3, lastName);
        pst.setString(4, firstName);
        pst.setString(5, middleName);
        pst.setString(6, birthdate);
        pst.setString(7, gender1);
        pst.setString(8, address1);
        pst.setString(9, email1);
        pst.setLong(10, mobile);
        pst.setString(11, status1);
        pst.setString(12, religion1);
        pst.execute();
    }catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

I have 13 columns and userid is autoincrement. But I don't know how do that you don't need to put the user id.

And I got this error. And I want Auto Increment ID. So no need to input right?

Column count doesn't match value count at row 1
JeraldPunx
  • 309
  • 3
  • 8
  • 18

4 Answers4

1

Remove the "userid" from the list of columns if you don't intend to supply a value to it.

I.e. INSERT INTO user (username, password, ...)

Kayaman
  • 72,141
  • 5
  • 83
  • 121
1

You are specifying 13 columns in your INSERT, but only 12 placeholders in the VALUES clause. The number of columns and values must match. Either you need to remove the userid column from your INSERT, or you need to add an additional placeholder (or literal value) to set its value.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
0

You can't insert values to AutoInc column, so just remove it from query:

insert into user(userName, password,...) values (and your values here)
Sergio
  • 6,900
  • 5
  • 31
  • 55
0

Is your database MySQL? If yes, you could refer to this post about inserting value to auto incremented column. How to insert data to MySQL having auto incremented primary key?

Community
  • 1
  • 1
kenshinji
  • 2,021
  • 4
  • 25
  • 39