C3P0

配置方法

 

#
#
c3p0.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
c3p0.jdbcUrl=jdbc:sqlserver://localhost:1433;database=databaseName
c3p0.user=sa
c3p0.password=sa1
c3p0.minPoolSize=2
c3p0.maxPoolSize=20

#c3p0.testConnectionOnCheckout=true
#c3p0.testConnectionOnCheckin=true

#c3p0.checkoutTimeout=2000
#c3p0.idleConnectionTestPeriod=5
#c3p0.maxConnectionAge=10
#c3p0.maxIdleTime=2
#c3p0.maxIdleTimeExcessConnections=1
#c3p0.propertyCycle=1
#c3p0.numHelperThreads=10
#c3p0.unreturnedConnectionTimeout=15
#c3p0.debugUnreturnedConnectionStackTraces=true
#c3p0.maxStatements=30
#c3p0.maxStatementsPerConnection=5
#c3p0.maxAdministrativeTaskTime=3
#c3p0.preferredTestQuery=SELECT 1
#c3p0.preferredTestQuery=SELECT a FROM emptyyukyuk WHERE a = 5
#c3p0.preferredTestQuery=SELECT a FROM testpbds WHERE a = 5
#c3p0.usesTraditionalReflectiveProxies=true
#c3p0.automaticTestTable=PoopyTestTable
#c3p0.acquireIncrement=4
#c3p0.acquireRetryDelay=1000
#c3p0.acquireRetryAttempts=60
#c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester
#c3p0.initialPoolSize=10
com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog
com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames
com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL

#com.mchange.v2.c3p0.VMID=poop

 
  /**
	 * 获得数据库的连接
	 *
	 * @return Connection
	 */
	public Connection getConnection() throws Exception {
		try{
			// 如果Connection为空
//			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//			connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=webSite;","sa","sa1");
//			//
//			if(connection==null){
//				Class.forName("oracle.jdbc.driver.OracleDriver");
//				connection=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.101:1521:orcl","dbweb","webdba");
//			}
			connection=new ComboPooledDataSource().getConnection();
			if (connection == null || connection.isClosed()) {
				if (dataSource == null) {
					dataSource = (DataSource) new InitialContext().lookup(DEFAULT_JNDI);
				}
				connection = dataSource.getConnection();
			}
		}catch (SQLException e) {
			log.warn("数据库连接失败:"+e.getMessage());
		}catch (Exception e) {
			log.error(e);
		}
		return connection;
	}
	public DataSource getDataSource() {
		return dataSource;
	}
 

你可能感兴趣的:(c3p0)