日期:2014-05-20 浏览次数:20833 次
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${user}" /> <property name="password" value="${password}" /> <property name="jdbcUrl" value="${jdbcUrl}" /> <property name="driverClass" value="${driverClass}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>//100 <property name="minPoolSize" value="${c3p0.minPoolSize}"/>//10 <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>//10 <property name="maxIdleTime" value="${c3p0.maxIdleTime}"/> //100 <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>//5 <!-- <property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}"/> //5 --> <property name="acquireRetryDelay" value="${c3p0.acquireRetryDelay}"/>//10 <property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>//true <property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"/>//100 <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>//60 <!-- <property name="numHelperThreads" value="${c3p0.numHelperThreads}"/>//5 --> </bean>
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; An attempt by a client to checkout a Connection has timed out.; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; public class ConnDB { private static DataSource ds = null; static { Context context; try { context = new InitialContext(); ds = (DataSource) context.lookup("java:comp/env/jdbc/bbs");//连接池名字 } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Connection getConnection2() { if (ds != null) { try { return ds.getConnection(); } catch (SQLException e) { e.printStackTrace(); } } return null; } }