public static void main(String[] args){
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
BasicDao dao = (BasicDao)bf.getBean("BasicDao");
DataSource ds = dao.getDataSource();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
 conn = ds.getConnection();
 conn.setAutoCommit(false);
 st = conn.createStatement();
 rs = st.executeQuery("select * from emp;");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(rs.next()){
System.out.println(rs.getBoolean(0));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="user" value="scott"></property>
<property name="password" value="tiger"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:oracle"></property>
<property name="minPoolSize" value="10"></property>
<property name="maxPoolSize" value="50"></property>
<property name="maxIdleTime" value="180"></property>
<property name="acquireIncrement" value="5"></property>
<property name="maxStatements" value="100"></property>
</bean>
我曾经尝试过把maxStatement属性改为0不过仍然出错:错误如下……
2010-4-6 18:30:08 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
INFO - MLog clients using log4j logging.
INFO - Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
DEBUG - MBean: com.mchange.v2.c3p0:type=PooledDataSource[1hge15x871mgbo56vlgosr|1e13d52] registered.
DEBUG - incremented pending_acquires: 1
DEBUG - incremented pending_acquires: 2
DEBUG - incremented pending_acquires: 3
DEBUG - incremented pending_acquires: 4
DEBUG - incremented pending_acquires: 5
DEBUG - incremented pending_acquires: 6
DEBUG - incremented pending_acquires: 7
DEBUG - incremented pending_acquires: 8
DEBUG - incremented pending_acquires: 9
DEBUG - incremented pending_acquires: 10
DEBUG - com.mchange.v2.resourcepool.BasicResourcePool@29e357 config: [start -> 3; min -> 10; max -> 50; inc -> 5; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 0; mox_resource_age -> 0; max_idle_time -> 180000; excess_max_idle_time -> 0; destroy_unreturned_resc_time -> 0; expiration_enforcement_delay -> 45000; break_on_acquisition_failure -> false; debug_store_checkout_exceptions -> false]
INFO - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge15x871mgbo56vlgosr|1e13d52, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge15x871mgbo56vlgosr|1e13d52, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@localhost:1521:oracle, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 180, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
DEBUG - acquire test -- pool size: 0; target_pool_size: 10; desired target? 1
DEBUG - awaitAvailable(): [unknown]
DEBUG - trace com.mchange.v2.resourcepool.BasicResourcePool@29e357 [managed: 0, unused: 0, excluded: 0]
DEBUG - An exception occurred while acquiring a poolable resource. Will retry.
java.sql.SQLException: 不支持的特性
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)
at oracle.jdbc.driver.OracleConnection.getHoldability(OracleConnection.java:3085)
at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:106)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:198)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
DEBUG - An exception occurred while acquiring a poolable resource. Will retry.
java.sql.SQLException: 不支持的特性
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)
at oracle.jdbc.driver.OracleConnection.getHoldability(OracleConnection.java:3085)
at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:106)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:198)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
DEBUG - An exception occurred while acquiring a poolable resource. Will retry.
后边是不停的循环报错……想请教各位大侠……谢谢~~~

解决方案 »

  1.   

    只要开始取connection就开始报错了……
      

  2.   

    hoho~~~抱歉抱歉……package com.dao;import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;import javax.sql.DataSource;import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;import com.mchange.v2.c3p0.ComboPooledDataSource;public class BasicDao { private ComboPooledDataSource dataSource = null; public ComboPooledDataSource getDataSource() {
    return dataSource;
    } public void setDataSource(ComboPooledDataSource dataSource) {
    this.dataSource = dataSource;
    }

    public static void main(String[] args){
    BeanFactory bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    BasicDao dao = (BasicDao)bf.getBean("BasicDao");
    DataSource ds = dao.getDataSource();
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
     conn = ds.getConnection();
     conn.setAutoCommit(false);
     st = conn.createStatement();
     rs = st.executeQuery("select * from emp;");
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    while(rs.next()){
    System.out.println(rs.getBoolean(0));
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}