| | |
| | | package com.sql; |
| | | import java.beans.PropertyVetoException; |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | |
| | | import com.mchange.v2.c3p0.ComboPooledDataSource; |
| | | |
| | | public class MysqlConnPool { |
| | | private ComboPooledDataSource mysql_ds = new ComboPooledDataSource(); |
| | | private int mSqlPort = 5306; |
| | | |
| | | public MysqlConnPool(String server_ip, int port, int conncount_max) |
| | | { |
| | | try { |
| | | init(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.setMaxPoolSize(conncount_max); |
| | | mysql_ds.setMinPoolSize(2); |
| | | mysql_ds.setIdleConnectionTestPeriod(60); |
| | | } |
| | | public Connection getConn() |
| | | { |
| | | Connection con = null; |
| | | try { |
| | | con = mysql_ds.getConnection(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return con; |
| | | } |
| | | |
| | | public int getSqlConnPort() { |
| | | return mSqlPort; |
| | | } |
| | | } |
| | | package com.sql;
|
| | | import java.beans.PropertyVetoException;
|
| | | import java.sql.Connection;
|
| | | import java.sql.SQLException;
|
| | |
|
| | | import com.mchange.v2.c3p0.ComboPooledDataSource;
|
| | |
|
| | | public class MysqlConnPool {
|
| | | private ComboPooledDataSource mysql_ds = new ComboPooledDataSource();
|
| | | private int mSqlPort = 5306;
|
| | | |
| | | public MysqlConnPool(String server_ip, int port, int conncount_max)
|
| | | {
|
| | | try {
|
| | | init(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 Connection getConn()
|
| | | {
|
| | | Connection con = null;
|
| | | try {
|
| | | con = mysql_ds.getConnection();
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return con;
|
| | | }
|
| | | |
| | | public int getSqlConnPort() {
|
| | | return mSqlPort;
|
| | | }
|
| | | }
|