i am using xammp database. and i want to get last ID from my database so that i can insert new stuff in it.
the code below doesnt get me the last it. its prints it is adding one next to last it. ex
7, 71, 711, 7111, 71111,
but i want ID to be 1, ... 7, 8, 9, 10, 11, 12 ...
try{
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection(url, "root", ""); //connect with xammp database
Statement sqlState = connect.createStatement();
//-------------------------------------------------------------------------------
//get last id
String sqlString = "Select * from Score";
ResultSet row = sqlState.executeQuery(sqlString);
while (row.next()) {
lastID = row.getInt(1);
}
//insert in database
sqlState.executeUpdate("insert into Score"+
"(ID, User_Name, ScoreValue)"+
"values('"+ lastID+1 +"', '"+userNameTemp +"', '"+ score +"')");
sqlState.close();
connect.close();
}
only part that doesnt workis the lastid. rest works fine.