java - How to insert empty row and get autoincrement id? -


i want add empty row table , autoincrement id in java. im not sure why im still getting userid=0. java class:

public class userprofiledao {     private dbconnectionmanager connectionmanager;     private static final string insert_user = "insert user_profile values(default)";     private int userid;      public userprofiledao(dbconnectionmanager connectionmanager) {         this.connectionmanager = connectionmanager;         try (connection connection = connectionmanager.getconnection()) {             try (preparedstatement preparedstatement = connection.preparestatement(insert_user)) {                 try (resultset generatedkey = preparedstatement.getgeneratedkeys()) {                     if (generatedkey.next()) {                         userid = generatedkey.getint(1);                     }                 }             }         } catch (sqlexception e) {             throw new runtimeexception(e);         }     }      public int getuserid() {         return userid;     } } 

you can use: lastval() next statement in current session , value


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -