| | |
| | | package com.sql;
|
| | |
|
| | | import com.mchange.v2.c3p0.ComboPooledDataSource;
|
| | | import java.beans.PropertyVetoException;
|
| | | import java.sql.Connection;
|
| | | import java.sql.SQLException;
|
| | |
|
| | | import com.mchange.v2.c3p0.ComboPooledDataSource;
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | |
|
| | | public class MysqlConnPool {
|
| | | private ComboPooledDataSource mysql_ds = new ComboPooledDataSource();
|
| | | private int mSqlPort = 5306;
|
| | | public static final int SQL_Type_MySQL = 1; //mysql
|
| | | public static final int SQL_Type_HanGao = 2; //瀚高
|
| | |
|
| | | public MysqlConnPool(String server_ip, int port, int conncount_max)
|
| | | {
|
| | | 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 init(String server_ip, int port, int conncount_max) throws PropertyVetoException
|
| | | {
|
| | | mSqlPort = port;
|
| | | mysql_ds.setDriverClass("com.mysql.jdbc.Driver");
|
| | | mysql_ds.setJdbcUrl("jdbc:mysql://" + server_ip + ":" + mSqlPort);
|
| | | mysql_ds.setUser("root");
|
| | | mysql_ds.setPassword("lmx8688139");
|
| | | //mysql_ds.setPassword("Dongli&12345678"); //清远电信数据库密码修改
|
| | | mysql_ds.setMaxPoolSize(conncount_max);
|
| | | mysql_ds.setMinPoolSize(2);
|
| | | mysql_ds.setIdleConnectionTestPeriod(60);
|
| | |
|
| | |
|
| | | 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.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 void initHG(String server_ip, int port, int conncount_max) throws PropertyVetoException
|
| | | {
|
| | | mSqlPort = port;
|
| | | mysql_ds.setDriverClass("com.highgo.jdbc.Driver");
|
| | | mysql_ds.setJdbcUrl("jdbc:highgo://localhost:5866/highgo");
|
| | | mysql_ds.setUser("sysdba");
|
| | | mysql_ds.setPassword("Lmx&8688139");
|
| | | mysql_ds.setMaxPoolSize(conncount_max);
|
| | | mysql_ds.setMinPoolSize(2);
|
| | | mysql_ds.setIdleConnectionTestPeriod(60);
|
| | | }
|
| | | public Connection getConn()
|
| | | {
|
| | | public Connection getConn() {
|
| | | Connection con = null;
|
| | | try {
|
| | | con = mysql_ds.getConnection();
|
| | | con = this.mysql_ds.getConnection();
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return con;
|
| | | }
|
| | | |
| | |
|
| | | public int getSqlConnPort() {
|
| | | return mSqlPort;
|
| | | 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
|
| | | */ |