Guest User

Untitled

a guest
Mar 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. public void deposit(int acc,int Amount) {
  2. try {
  3. String host= "jdbc:derby://localhost:1527/ZaiLab";
  4. String uname= "siduduzo";
  5. String upass ="Password01";
  6. Connection con = DriverManager.getConnection( host, uname, upass );
  7.  
  8. Statement stmt = con.createStatement( );
  9.  
  10. if(Amount<1000) {
  11. JOptionPane.showMessageDialog( null,"Sorry! the Minimum you can deposit on a savings account is R1000");
  12. } else {
  13. try (PreparedStatement checkAccountExists = con.prepareStatement("SELECT 1 FROM SAVINGS WHERE ACCOUNTNUMBER = ?")) {
  14. checkAccountExists.setInt(1, acc);
  15.  
  16. try (ResultSet RS = checkAccountExists.executeQuery()) {
  17. int currentbal = RS.getInt("BALANCE");
  18. int newbalance = currentbal+Amount;
  19.  
  20. if (RS.next()) {
  21. String sql = "UPDATE SAVINGS WHERE ACCOUNTNUMBER =" +acc+ "SET BALANCE = "+newbalance;
  22. stmt.executeUpdate(sql);
  23. JOptionPane.showMessageDialog( null,"you have made a deposit to "+acc);
  24. } else {
  25. JOptionPane.showMessageDialog( null,"Invalid Account Number");
  26. }
  27. }
  28. }
  29. }
  30. } catch ( SQLException err ) {
  31. System.out.println( err.getMessage( ) );
  32. }
  33. }
  34.  
  35. try (PreparedStatement checkAccountExists = con.prepareStatement(
  36. "SELECT BALANCE FROM SAVINGS WHERE ACCOUNTNUMBER = ?")) {
  37. checkAccountExists.setInt(1, acc);
  38.  
  39. try (ResultSet RS = checkAccountExists.executeQuery()) {
  40. if (RS.next()) {
  41. int currentbal = RS.getInt("BALANCE");
  42. int newbalance = currentbal + Amount;
  43.  
  44. try (PreparedStatement stmt = con.prepareStatement(
  45. "UPDATE SAVINGS SET BALANCE = ? WHERE ACCOUNTNUMBER = ?")){
  46.  
  47. stmt.setInt(1, newbalance);
  48. stmt.setInt(2, acc);
  49.  
  50. stmt.executeUpdate();
  51. JOptionPane.showMessageDialog(null, "you have made a deposit to "+acc);
  52. }
  53.  
  54. } else {
  55. JOptionPane.showMessageDialog(null, "Invalid Account Number");
  56. }
  57. }
  58. }
  59.  
  60. SELECT 1 FROM SAVINGS WHERE ACCOUNTNUMBER = ?
  61.  
  62. checkAccountExists.setInt(1, acc);
  63.  
  64. SELECT BALANCE FROM SAVINGS WHERE ACCOUNTNUMBER = ?
  65.  
  66. its change all the records in the column to the same record
  67.  
  68. sql = "SELECT * FROM department INNER JOIN employee ON department.depno=
  69. employee.depno ";
  70. resultSet = statement.executeQuery(sql);
  71.  
  72. sql2="update employee set empage=? " ;
  73. ps=connection.prepareStatement(sql2);
  74. while (resultSet.next()){
  75. empage=resultSet.getInt("empage");
  76. if(empage>50){ l= empage-3;
  77. //statement.executeUpdate(sql2);
  78. ps.setInt(1,l);
  79. ps.executeUpdate();
  80. ps.addBatch();
  81. } }
  82.  
  83. its change all the records in the column to the same record
Add Comment
Please, Sign In to add comment