⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountdao.java

📁 Java banking application with GUI add/delete/update new account partially generic GUI
💻 JAVA
字号:
import java.sql.ResultSet;
import java.sql.Statement;

public class AccountDAO {

  private String query;
  private ServiceLocater sl=ServiceLocater.getInstance();
  private Statement statement=sl.createStatement();

  public boolean addAccount(String holdername,String type,double balance) {
    int result = 0;
    try {
      String query ="Insert into Account (holdername,type,balance) values ('" +
          holdername+"','"+ type + "'," + balance + ")";
      result = statement.executeUpdate(query);

    }catch (Exception e) {
      System.out.println("Exception in addNewAccount1 " + e);
    }
    if (result == 1)
          return true;
    return false;
  }

  public ResultSet getAccount() {
	ResultSet Results=null;
    try {

      query = "SELECT accountnumber,holdername,type,balance FROM Account";
      Results=statement.executeQuery(query);
    }
    catch (Exception e) {
      System.out.println("getAccount()"+e);
    }

    return Results;
  }

  public ResultSet getAccount(int accountno)
  {
	ResultSet Results=null;
  try {
    query = "SELECT * FROM Account where accountnumber="+accountno;
    Results=statement.executeQuery(query);
  }
  catch (Exception e) {
    System.out.println("Exception in getAccount(String accountno) " + e);
  }
  return Results;
}


  public ResultSet searchAccount(int pid, String holdername, String type,double balance) {
	  ResultSet Results=null;
    try {
      query = "SELECT accountnumber,holdername,type,balance FROM Account ";
      String temp="";

      if (pid!=0) {
        if(temp.equals(""))
          temp="where accountnumber="+pid;
        else
          temp+=" AND accountnumber="+pid;
      }

      if (!holdername.equals("")) {
        if(temp.equals(""))
          temp="where holdername like '" + holdername + "'";
        else
          temp+=" AND holdername like '"+holdername+"'";
      } 
     if (!type.equals("")) {
        if(temp.equals(""))
          temp="where type like '" + type + "'";
        else
          temp+=" AND type like '"+type+"'";
      }
      if (balance!=0) {
        if(temp.equals(""))
          temp=" where balance<=" + balance + "";
        else
          temp+=" AND balance<=" + balance + "";
      }
      System.out.println("Query " + query+temp);
      Results = statement.executeQuery(query+temp);
    }
    catch (Exception e) {
      System.out.println("Exception in searchAccount " + e);
    }
    return Results;

  }

  public boolean updateAccount(int accountno,String holdername,String type,double balance) {
    int result = 0;
    try {
      String query ="Update Account set type='"+type+"',holdername='"+holdername +
      "',balance="+balance+" where accountnumber="+accountno;
      result = statement.executeUpdate(query);

    }catch (Exception e) {
      System.out.println("Exception in updateAccount " + e);
    }
    if (result == 1)
          return true;
    return false;
  }

  public boolean deleteAccount(int pid) {

    try {

      query = "Delete FROM Account where accountnumber="+pid;
      int result = statement.executeUpdate(query);
      if(result==1)
      return true;
    }
    catch (Exception e) {
      System.out.println("getAccount()"+e);
    }
    return false;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -