title: check if value (Accountnumber) exist in a java database
body: <p>I have the following method in a class called savings, am using JDBC database to save and view data on java application.</p>
  
  <p>I have SAVINGS table in my database <strong>ZaiLab</strong> with the following fields,</p>
  
  <pre><code>ID,ACCOUNTNUMBER,CUSTOMERNAME,BALANCE,MINMUM)
  </code></pre>
  
  <p>and the following VALUEs will be entered by the user using JOPtionPane.</p>
  
  <pre><code>(id,accountNumber,customername,balance,minmum);
  </code></pre>
  
  <p>the application should then check if <strong>accountNumber</strong> entered by the user already exist, if not it should save the record to a table SAVINGS, if yes it should display the appropriate message. "Account already exist". </p>
  
  <pre><code>public void openSavingsAccount(int Id, 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();
  
          String SQL = "SELECT * FROM SAVINGS";
          ResultSet rs = stmt.executeQuery(SQL);
  
          int minmum = 1000;
          balance = minmum;
  
          while (rs.next()) {
              int acc_col = rs.getInt("ACCOUNTNUMBER");
              if (acc_col == accountNumber) {
                  JOptionPane.showMessageDialog(null, "Sorry, account " + accountNumber
                          + " aready Exist");
              } else if (Amount &lt; minmum) {
                  JOptionPane.showMessageDialog(null, "Can not Open the Account, Minimum amount to deposit must be R1000");
              } else {
  
                  balance = balance + Amount;
                  id = Id;
                  stmt.executeUpdate("INSERT INTO `SAVINGS`(ID,ACCOUNTNUMBER,CUSTOMERNAME,BALANCE,MINMUM)VALUE ('" + id + "','" + accountNumber + "','" + customername + "'," + balance + ",'" + minmum + "')");
  
              }
  
          }
  
      } catch (SQLException err) {
          System.out.println(err.getMessage());
      }
  
  }
  </code></pre>