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:
IdUsuariINT NOT NULL AUTO_INCREMENT,NicknameVARCHAR(50) NOT NULL,DataRegistreDATE NOT NULL,DataDarrerAccesDATE NOT NULL,NumLlistesINT NOT NULL DEFAULT 0,PasswordVARCHAR(10) NOT NULL,AdminINT 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!
PreparedStatementfor any sort of user input!PreapredStatement, see Using Prepared Statements for more details408duplicate questions to be exact which is in itself a big enough close reason.