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

📄 daofactory.java

📁 struts的一些用的书籍
💻 JAVA
字号:
package app16a.dao;

import app16a.util.Config;

public class DAOFactory {
  private static String databaseType;
  private static DAOFactory instance;
  
  static {
  	instance = new DAOFactory();  
  }
  private DAOFactory() {
    databaseType = Config.getInstance().getValue("dbType").toString();
  }
  public static DAOFactory getInstance() {
    return instance;
  }
  
  public CustomerDAO getCustomerDAO() {
    String className = null;
    if (databaseType!=null) {
      if (databaseType.equalsIgnoreCase("mysql")) {         
        className = "app16a.dao.CustomerDAOMySQLImpl"; 
      }
      else if (databaseType.equalsIgnoreCase("oracle")) {
        className = "app16a.dao.CustomerDAOOracleImpl";
      }
    }
    if (className==null)
      return null;
    CustomerDAO customerDAO = null;
    Class clazz = null;
    try {
      clazz = Class.forName(className);
    }
    catch (ClassNotFoundException e) {
      System.out.println(e.toString());
    }
    if (clazz!=null) {
      try {
        customerDAO = (CustomerDAO) clazz.newInstance();
      }
      catch (Exception e) {
          System.out.println(e.toString());
      }
    }
    return customerDAO;  
  }
}

⌨️ 快捷键说明

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