package som.gu.core; import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import com.gu.bean.configuration; /** * 获得配置信息,维持连接管理 * @author 谷 * */ public class DBManager { private static configuration conf; static{ Properties pro=new Properties(); try { pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } conf=new configuration(); conf.setDriver(pro.getProperty("driver")); conf.setUrl(pro.getProperty("url")); conf.setUsingDB(pro.getProperty("usingDB")); conf.setAdmin(pro.getProperty("admin")); conf.setAd_pass(pro.getProperty("ad_pass")); conf.setPoPackage(pro.getProperty("poPackage")); conf.setSrcPath(pro.getProperty("srcPath")); } /** * 封装数据库的链接,资源关闭等方法 */ public static Connection getConnect(){ Connection con=null; try { // Class.forName("com.mysql.jdbc.Driver"); Class.forName(conf.getDriver()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { con=DriverManager.getConnection(conf.getUrl(), conf.getAdmin(), conf.getAd_pass()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return con; } public static void closeRes(ResultSet res,Statement ps,Connection con){ try { if(res!=null){ res.close(); } if(ps!=null){ ps.close(); } if(con!=null){ con.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }