2012-11-22 3 views
0

저는 간단한 서블릿을 사용하여 웹 페이지를 개발했습니다. 여기 내가 DB 연결을 선언하기 위해 하나의 컨텍스트 파일을 사용하고 있습니다.컨텍스트 파일에서 연결 풀을 설정하는 방법은 무엇입니까?

<?xml version="1.0" encoding="UTF-8"?> 
<Context> 
<Resource name="jdbc/red" auth="Container" type="javax.sql.DataSource" 
     maxActive="50" timeBetweenEvictionRunsMillis="3600000" 
     minEvictableIdleTimeMillis="3600000" 
     maxIdle="30" maxWait="10000" username="root" 
     password="root" driverClassName="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost:3306/red" 
     defaultAutoCommit="false" > 

</Resource> 
</Context> 

그리고 난 서블릿 페이지에서 web.xml을

<resource-ref> 
    <description>Mysql datasource</description> 
    <res-ref-name>jdbc/red</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

에서 설정 한 내 문제는 연결이 50 회 오류를 구축 할 때입니다

Context ctx=new InitialContext(); 
    DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/red"); 
    con=ds.getConnection(); 
    state=con.createStatement(); 
    rs=state.executeQuery(s); 
    rs.close(); 
    con.close(); 
    ctx.close(); 

은 다음과 같이 발생합니다

SEVERE: Servlet.service() for servlet jsp threw exception 

ja va.util.NoSuchElementException : 유휴 상태의 객체를 기다리는 시간 초과 org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject (GenericObjectPool.java:1171) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection에서 (PoolingDataSource.java:106) (BasicDataSource.java:1044)

컨텍스트 CTX = 새의 InitialContext(); 120 : DataSource ds = (DataSource) ctx.lookup ("java : comp/env/jdbc/red"); 121 : con = ds.getConnection();

답변

0

SET GLOBAL max_connections = 500;을 실행하거나 MySQL을 다시 시작하십시오. 이 링크를 클릭하면 문제를 해결하는 데 도움이됩니다. here

관련 문제