Guest User

Untitled

a guest
Oct 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public long saveOrder(Order order) {
  2. long orderId = 0;
  3. try (Connection conn = MyDataSource.getDataSource().getConnection();
  4. PreparedStatement ps = conn.prepareStatement("INSERT INTO orders(id, order_number) VALUES (NEXT VALUE FOR seq1, ?)",
  5. PreparedStatement.RETURN_GENERATED_KEYS)) {
  6.  
  7. ps.setString(1, order.getOrderNumber());
  8. ps.execute();
  9.  
  10. ResultSet rs = ps.getResultSet();
  11. if (rs.next()) {
  12. orderId = rs.getLong(1);
  13. }
  14.  
  15. } catch (Exception e) {
  16. throw new RuntimeException(e);
  17. }
  18. return orderId;
  19. }
Add Comment
Please, Sign In to add comment