ConnDB.java~7~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:1k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package core;
  2. import java.sql.*;
  3. import java.util.Properties;
  4. public class ConnDB {
  5.     public Connection conn=null;
  6.     public ResultSet rs=null;
  7.     public Statement stmt=null;
  8.     private static String propFileName="connDB.properties";
  9.     private static Properties prop=new Properties();
  10.     private static String dbClassName =
  11.     "com.mysql.jdbc.Driver";
  12.     private static String dbUrl =
  13.     "jdbc:mysql://127.0.0.1:3306/db_libraryManage";
  14.     private static String dbUser = "admin";
  15.     private static String dbPwd = "111";
  16.     private static void loadProperty() {
  17.         try {
  18.             prop.load(new FileInputStream(propFileName)); //通过文件输入流对象加载Properties文件
  19.             dbClassName = prop.getProperty("DB_CLASS_NAME");
  20.             dbUrl = prop.getProperty("DB_URL",
  21.                                      "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_shop");
  22.             dbUser = prop.getProperty("DB_USER", "admin");
  23.             dbPwd = prop.getProperty("DB_PWD", "111");
  24.         } catch (Exception e) {
  25.             e.printStackTrace();
  26.         }
  27.     }
  28. }