Advertisement
Trollfacedk

Untitled

Jan 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. //Update a Konto
  2. public void updateKontoSaldo(Konto konto)
  3. {
  4. try (
  5. Connection connection = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9001/mydb", "SA", "");
  6. PreparedStatement updateKonto = connection.prepareStatement("update konto set saldo = ? where kontonummer = ?");
  7. PreparedStatement findDataForCurrentKunde = connection.prepareStatement("select * from konto where kontonummer = ?");
  8. )
  9. {
  10.  
  11. findDataForCurrentKunde.setInt(1, konto.getKontoNumber());
  12. ResultSet existingKonto = findDataForCurrentKunde.executeQuery();
  13.  
  14. if (existingKonto.next())
  15. {
  16. updateKonto.setDouble(1, konto.getSaldo());
  17. updateKonto.setInt(2, konto.getKontoNumber());
  18. updateKonto.executeUpdate();
  19. }
  20. }
  21. catch (SQLException e)
  22. {
  23. System.out.println(e.getMessage());
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement