Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public long saveOrder(Order order) {
- long orderId = 0;
- try (Connection conn = MyDataSource.getDataSource().getConnection();
- PreparedStatement ps = conn.prepareStatement("INSERT INTO orders(id, order_number) VALUES (NEXT VALUE FOR seq1, ?)",
- PreparedStatement.RETURN_GENERATED_KEYS)) {
- ps.setString(1, order.getOrderNumber());
- ps.execute();
- ResultSet rs = ps.getResultSet();
- if (rs.next()) {
- orderId = rs.getLong(1);
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return orderId;
- }
Add Comment
Please, Sign In to add comment