数据库类型:1为MYSQL,默认为1。
DBType=1
MySQL 数据库连接信息
MySQL 数据库驱动程序
MySQLDriver=org.gjt.mm.mysql.Driver
MySQL数据库连接字符串。
127.0.0.1:3306 为数据库地址和端口
webDB 为数据库名,user 为登录用户名,password 为登录密码。请自行更改。
MySQLURL=jdbc:mysql://192.168.52.11:3306/webDB?user=root&password=root&useUnicode=true&charact
erEncoding=UTF-8
还可以继续添加其它的数据库。
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){
//e.printStackTrace();
//return "操作数据库出错,请仔细检查" ;
//System.err.println(e.getMessage());
}
return conn;
}