package com.sql;
|
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import java.beans.PropertyVetoException;
|
import java.sql.Connection;
|
import java.sql.SQLException;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
public class MysqlConnPool {
|
public static final int SQL_Type_MySQL = 1; //mysql
|
public static final int SQL_Type_HanGao = 2; //嫸ß
|
|
private ComboPooledDataSource mysql_ds = new ComboPooledDataSource();
|
private int mSqlPort = 3360;
|
private Logger logger;
|
|
public MysqlConnPool(String server_ip, int port, int conncount_max,int sql_type) {
|
try {
|
logger = LogManager.getLogger(this);
|
logger.info("SqlServerType:" + getSqlServerType(sql_type));
|
if(SQL_Type_HanGao == sql_type) {
|
//嫸ßÊý¾Ý¿â
|
initHG(server_ip, port, conncount_max);
|
} else {
|
//ĬÈÏÁ¬½ÓMySQL
|
init(server_ip,port,conncount_max);
|
}
|
} catch (PropertyVetoException e) {
|
e.printStackTrace();
|
}
|
}
|
public MysqlConnPool(String server_ip, int port, int conncount_max) {
|
try {
|
initHG(server_ip, port, conncount_max);
|
} catch (PropertyVetoException e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
public void initHG(String server_ip, int port, int conncount_max) throws PropertyVetoException {
|
this.mSqlPort = port;
|
this.mysql_ds.setDriverClass("com.highgo.jdbc.Driver");
|
this.mysql_ds.setJdbcUrl("jdbc:highgo://" + server_ip + ":" + port + "/highgo");
|
this.mysql_ds.setUser("sysdba");
|
// this.mysql_ds.setPassword("Lmx&8688139");
|
this.mysql_ds.setPassword("Fg001@HDW"); //ÐÂÃÜÂë
|
this.mysql_ds.setMaxPoolSize(conncount_max);
|
this.mysql_ds.setMinPoolSize(2);
|
this.mysql_ds.setIdleConnectionTestPeriod(300);
|
}
|
|
public void init(String server_ip, int port, int conncount_max) throws PropertyVetoException {
|
this.mSqlPort = port;
|
this.mysql_ds.setDriverClass("com.mysql.jdbc.Driver");
|
this.mysql_ds.setJdbcUrl("jdbc:mysql://" + server_ip + ":" + this.mSqlPort);
|
this.mysql_ds.setUser("root");
|
this.mysql_ds.setPassword("lmx8688139");
|
this.mysql_ds.setMaxPoolSize(conncount_max);
|
this.mysql_ds.setMinPoolSize(2);
|
this.mysql_ds.setIdleConnectionTestPeriod(300);
|
}
|
|
public String getSqlServerType(int sqlServerType) {
|
String sqltypestr = "MySQL";
|
switch (sqlServerType) {
|
case SQL_Type_MySQL:
|
sqltypestr = "MySQL";
|
break;
|
case SQL_Type_HanGao:
|
sqltypestr = "HanGao";
|
break;
|
default:sqltypestr = "MySQL";
|
break;
|
}
|
return sqltypestr;
|
}
|
|
public Connection getConn() {
|
Connection con = null;
|
try {
|
con = this.mysql_ds.getConnection();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
return con;
|
}
|
|
public int getSqlConnPort() {
|
return this.mSqlPort;
|
}
|
}
|
|
/*
|
* Location:
|
* C:\Users\LiJun\Desktop\¹«Ë¾¸÷ÖÖÉ豸×ÊÁÏ\9600ÏÔʾģ¿éÏà¹ØÎļþ\ºǫ́³ÌÐò\2018-09-07\BattFBS9600XSP.
|
* jar Qualified Name: com.sql.MysqlConnPool JD-Core Version: 0.6.2
|
*/
|