package com.hkd.basedao;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class BaseDao{
String DBUser;
String DBPwd;
String DBHost;//服务器地址
String DBName;
int Port;
int Port2;
int DBType;//1 mysql 2 sqlserver 3 oracle;
Connection conn;
PreparedStatement ps;
public ResultSet rs;
public BaseDao(){
Properties pro=new Properties();
InputStream is=BaseDao.class.getClassLoader().getResourceAsStream("database.properties");
try {
pro.load(is);
DBUser=pro.getProperty("DBUser");
DBPwd=pro.getProperty("DBPwd");
DBHost=pro.getProperty("DBHost");
DBName=pro.getProperty("DBName");
Port=Integer.parseInt(pro.getProperty("Port"));
DBType=Integer.parseInt(pro.getProperty("DBType"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void open(){
try {
if(DBType==1){
Class.forName("com.mysql.jdbc.Driver");
// jdbc:mysql://localhost:3306/数据库名
conn=DriverManager.getConnection("jdbc:mysql://"+DBHost+":"+Port+"/"+DBName, DBUser, DBPwd);
}else if(DBType==2){
Class.forName("com.microsoft.sqlserver.sqlserverDriver");
//jdbc:sqlserver://localhost:1433;databasename=myschool
conn=DriverManager.getConnection("jdbc:sqlserver://"+DBHost+":"+Port2+";databasename="+DBName, DBUser, DBPwd);
}else{
}
} catch (Exception e){
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class BaseDao{
String DBUser;
String DBPwd;
String DBHost;//服务器地址
String DBName;
int Port;
int Port2;
int DBType;//1 mysql 2 sqlserver 3 oracle;
Connection conn;
PreparedStatement ps;
public ResultSet rs;
public BaseDao(){
Properties pro=new Properties();
InputStream is=BaseDao.class.getClassLoader().getResourceAsStream("database.properties");
try {
pro.load(is);
DBUser=pro.getProperty("DBUser");
DBPwd=pro.getProperty("DBPwd");
DBHost=pro.getProperty("DBHost");
DBName=pro.getProperty("DBName");
Port=Integer.parseInt(pro.getProperty("Port"));
DBType=Integer.parseInt(pro.getProperty("DBType"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void open(){
try {
if(DBType==1){
Class.forName("com.mysql.jdbc.Driver");
// jdbc:mysql://localhost:3306/数据库名
conn=DriverManager.getConnection("jdbc:mysql://"+DBHost+":"+Port+"/"+DBName, DBUser, DBPwd);
}else if(DBType==2){
Class.forName("com.microsoft.sqlserver.sqlserverDriver");
//jdbc:sqlserver://localhost:1433;databasename=myschool
conn=DriverManager.getConnection("jdbc:sqlserver://"+DBHost+":"+Port2+";databasename="+DBName, DBUser, DBPwd);
}else{
}
} catch (Exception e){