爱笑的眼睛_1636691679 发表于2021-11-12 12:37
package mingrisoft;
import java.sql.*;
import java.util.*;
import java.io.*;
import mingrisoft.Function;
public class DBConnection
{
private String FileName;
private int DBType;
private Connection conn;
private String MySqlDriver;
private String MySqlURL;
public DBConnection()
{
conn = null;
}
public Connection getConn()
{
DBType= new Function().StrToInt(getPara("DBType"));
switch(DBType)
{
case 1:return(getConnToMySql());
default:return null;
}
}
public String getPara(String ParaName)
{
FileName="../DBConfig.property";
Properties prop= new Properties();
try
{
InputStream is=getClass().getResourceAsStream(FileName);
prop.load(is);
if(is!=null) is.close();
}
catch(Exception e) {
return "Error!";
}
return prop.getProperty(ParaName);
}
public Connection getConnToMySql()
{
try{
MySqlDriver = getPara("MySQLDriver");
MySqlURL = getPara("MySQLURL");
Class.forName(MySqlDriver).newInstance();
conn = DriverManager.getConnection(MySqlURL);
}catch(Exception e){
}
return conn;
}
}
老师,这数据库配置吗