Created
October 9, 2012 19:53
-
-
Save ipolevoy/3861026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PreparedStatement ps = connection.prepareStatement("INSERT INTO users (first_name, email, last_name) VALUES (?, ?, ?)", new String[]{"id"}); | |
ps.setObject(1, "John"); | |
ps.setObject(2, "Doe"); | |
ps.setObject(3, "john@doe.com"); | |
ps.executeUpdate(); | |
ResultSet rs = ps.getGeneratedKeys(); | |
rs.next(); | |
Object id = rs.getObject(1); | |
System.out.println("Generated Id value: " + id); | |
System.out.println("Generated Id class: " + id.getClass()); | |
Statement s = connection.createStatement(); | |
ResultSet rs1 = s.executeQuery("select * from users"); | |
rs1.next(); | |
Object realId = rs1.getObject("id"); | |
System.out.println("realId Id value: " + realId); | |
System.out.println("realId Id class: " + realId.getClass()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Generated Id value: 1
Generated Id class: class java.lang.Long
realId Id value: 1
realId Id class: class java.lang.Integer