java sql insert return id

Solutions on MaxInterview for java sql insert return id by the best coders in the world

showing results for - "java sql insert return id"
Iris
19 Oct 2017
1Resultset result;
2PreparedStatement prep;
3String query = "INSERT INTO myRel (data) VALUES (?)";
4
5prep = db.prepareStatement(query ,Statement.RETURN_GENERATED_KEYS);
6
7result = prep.getGeneratedKeys();
8
9if(result.next() && result != null){
10   System.out.println("Key: " + result.getInt(1));
11} else {
12   System.out.println("No, Nop nada");
13}
14