c3p0连接Oracle数据库设置v$session.program

高增光 发布于 2014/04/30 14:59
阅读 686
收藏 0
2014-4-30 14:49:58 com.mchange.v2.log.MLog <clinit>
信息: MLog clients using java 1.4+ standard logging.
2014-4-30 14:49:58 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.0 [built 11-July-2005 00:43:29 -0400; debug? true; trace: 10]
2014-4-30 14:49:58 com.mchange.v2.c3p0.PoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource@97a560[ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> inspur_nwom_gaozg, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 97a560, idleConnectionTestPeriod -> -1, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@10.224.133.213:1521:NWOM, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {v$session.osuser=Administrator, v$session.machine=GAOZG, v$session.program=My Program Name}, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, usesTraditionalReflectiveProxies -> false ]
2014-4-30 14:50:27 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1d64c37 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
java.sql.SQLException: Connections could not be acquired from the underlying database!
 at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
 at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
 at com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
 at com.inspur.gaozg.utils.ConnectionFactory.getConnection(ConnectionFactory.java:54)
 at com.inspur.gaozg.dao.EquipmentDao.getEquipByCondition(EquipmentDao.java:27)
 at com.inspur.gaozg.main.main.main(main.java:25)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
 at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
 at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
 ... 5 more
Exception in thread "main" java.lang.NullPointerException
 at com.inspur.gaozg.dao.EquipmentDao.getEquipByCondition(EquipmentDao.java:62)
 at com.inspur.gaozg.main.main.main(main.java:25)
The sql->[SELECT * FROM V_BJ_LC_EQUIPMENT WHERE 1=1  AND EQUIPMENT_IP='10.224.133.209' AND USER_NAME='nwom' ]
java.lang.NullPointerException
2014-4-30 14:50:27 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1f17e77 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).

 

 

package com.inspur.gaozg.utils;

import java.beans.PropertyVetoException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;

import com.mchange.v2.c3p0.ComboPooledDataSource;
public class ConnectionFactory 
{
	private ConnectionFactory(){}       
    private static ComboPooledDataSource ds = null;   
    static
    {
        try
        {
        	Properties properties = new java.util.Properties();
        	properties.put("v$session.program", "My Program Name");
        	properties.put("v$session.osuser", System.getProperty("user.name").toString());   
        	properties.put("v$session.machine", InetAddress.getLocalHost().getCanonicalHostName());   
        	properties.put("v$session.program", "My Program Name");  
        	Map<String,String> map = new ReadProperties().readFile(Thread.currentThread().getContextClassLoader().getResource("").getPath()+"jdbc.properties") ;
    		String driverName = map.get("jdbc.driver") ;
    		String dbURL = map.get("jdbc.url") ;
    		String userName = map.get("jdbc.username") ;
    		String userPwd = map.get("jdbc.password") ;
    		String description = map.get("jdbc.description") ;
    		int    max_size = Integer.valueOf(map.get("datasource.maxPoolSize"));
    		int    min_size = Integer.valueOf(map.get("datasource.minPoolSize")) ;
            ds = new ComboPooledDataSource();   // 设置JDBC的Driver类   
            ds.setDriverClass(driverName);  // 参数由 Config 类根据配置文件读取
            ds.setJdbcUrl(dbURL);    // 设置JDBC的URL
            ds.setUser(userName);   // 设置数据库的登录用户名  
            ds.setPassword(userPwd);  // 设置数据库的登录用户密码
            ds.setMaxPoolSize(max_size);   // 设置连接池的最大连接数
            ds.setMinPoolSize(min_size); // 设置连接池的最小连接数
            ds.setDescription(description);
            ds.setProperties(properties);
            ds.setTestConnectionOnCheckout(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
			e.printStackTrace();
		}   
    }   
    public static synchronized Connection getConnection()
    {   
        Connection con = null;   
        try {   
            con = ds.getConnection();   
        } catch (SQLException e) {   
            e.printStackTrace();   
        }   
        return con;   
    }
}


 

加载中
返回顶部
顶部