Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mca", "root", "root");
- PreparedStatement pst = conn.prepareStatement("INSERT INTO TESTE (NOME) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
- pst.setString(1, "FIERODD");
- pst.executeUpdate();
- ResultSet rs = pst.getGeneratedKeys();
- int id = 0;
- if(rs.next()){
- id = rs.getInt(1);
- }
- System.out.println("Id gerado pelo insert foi " + id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement