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!
PreparedStatement
for any sort of user input! – DragondraikkPreapredStatement
, see Using Prepared Statements for more details – MadProgrammer408
duplicate questions to be exact which is in itself a big enough close reason. – Hanky Panky