Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void deposit(int acc,int Amount) {
- try {
- String host= "jdbc:derby://localhost:1527/ZaiLab";
- String uname= "siduduzo";
- String upass ="Password01";
- Connection con = DriverManager.getConnection( host, uname, upass );
- Statement stmt = con.createStatement( );
- if(Amount<1000) {
- JOptionPane.showMessageDialog( null,"Sorry! the Minimum you can deposit on a savings account is R1000");
- } else {
- try (PreparedStatement checkAccountExists = con.prepareStatement("SELECT 1 FROM SAVINGS WHERE ACCOUNTNUMBER = ?")) {
- checkAccountExists.setInt(1, acc);
- try (ResultSet RS = checkAccountExists.executeQuery()) {
- int currentbal = RS.getInt("BALANCE");
- int newbalance = currentbal+Amount;
- if (RS.next()) {
- String sql = "UPDATE SAVINGS WHERE ACCOUNTNUMBER =" +acc+ "SET BALANCE = "+newbalance;
- stmt.executeUpdate(sql);
- JOptionPane.showMessageDialog( null,"you have made a deposit to "+acc);
- } else {
- JOptionPane.showMessageDialog( null,"Invalid Account Number");
- }
- }
- }
- }
- } catch ( SQLException err ) {
- System.out.println( err.getMessage( ) );
- }
- }
- try (PreparedStatement checkAccountExists = con.prepareStatement(
- "SELECT BALANCE FROM SAVINGS WHERE ACCOUNTNUMBER = ?")) {
- checkAccountExists.setInt(1, acc);
- try (ResultSet RS = checkAccountExists.executeQuery()) {
- if (RS.next()) {
- int currentbal = RS.getInt("BALANCE");
- int newbalance = currentbal + Amount;
- try (PreparedStatement stmt = con.prepareStatement(
- "UPDATE SAVINGS SET BALANCE = ? WHERE ACCOUNTNUMBER = ?")){
- stmt.setInt(1, newbalance);
- stmt.setInt(2, acc);
- stmt.executeUpdate();
- JOptionPane.showMessageDialog(null, "you have made a deposit to "+acc);
- }
- } else {
- JOptionPane.showMessageDialog(null, "Invalid Account Number");
- }
- }
- }
- SELECT 1 FROM SAVINGS WHERE ACCOUNTNUMBER = ?
- checkAccountExists.setInt(1, acc);
- SELECT BALANCE FROM SAVINGS WHERE ACCOUNTNUMBER = ?
- its change all the records in the column to the same record
- sql = "SELECT * FROM department INNER JOIN employee ON department.depno=
- employee.depno ";
- resultSet = statement.executeQuery(sql);
- sql2="update employee set empage=? " ;
- ps=connection.prepareStatement(sql2);
- while (resultSet.next()){
- empage=resultSet.getInt("empage");
- if(empage>50){ l= empage-3;
- //statement.executeUpdate(sql2);
- ps.setInt(1,l);
- ps.executeUpdate();
- ps.addBatch();
- } }
- its change all the records in the column to the same record
Add Comment
Please, Sign In to add comment