public boolean update(Payment payment) { PreparedStatement statement = null; String sql = "UPDATE payment SET id_transaction = " + payment.getIdTransaction() + ", lens_price = " + payment.getLensPrice() + ", frame_price = " + payment.getFramePrice() + ", amount = " + payment.getAmount() + ", dp = " + payment.getDp() + ", agency = " + payment.getAgency() + ", variance= " + payment.getVariance() + " WHERE id_payment = " + payment.getIdPayment(); try { statement = (PreparedStatement) connection.prepareStatement(sql); statement.executeUpdate(); System.out.println(sql); return true; } catch (SQLException ex) { Logger.getLogger(PaymentDAO.class.getName()).log(Level.SEVERE, null, ex); return false; } finally { if (statement != null) { try { statement.close(); } catch (SQLException ex) { Logger.getLogger(PaymentDAO.class.getName()).log(Level.SEVERE, null, ex); } } } }
public boolean insert(Payment payment) { PreparedStatement statement = null; String sql = "INSERT INTO payment VALUES (" + payment.getIdPayment() + ", " + payment.getIdTransaction() + ", " + payment.getLensPrice() + ", " + payment.getFramePrice() + ", " + payment.getAmount() + ", " + payment.getDp() + ", " + payment.getAgency() + ", " + payment.getVariance() + ")"; try { statement = (PreparedStatement) connection.prepareStatement(sql); statement.executeUpdate(); return true; } catch (SQLException ex) { Logger.getLogger(PaymentDAO.class.getName()).log(Level.SEVERE, null, ex); return false; } finally { if (statement != null) { try { statement.close(); } catch (SQLException ex) { Logger.getLogger(PaymentDAO.class.getName()).log(Level.SEVERE, null, ex); } } } }