Dear All, I am doing connection pooling with tomcat 7.0.39 and MySQL 5.5.After searching on google and with your help i have done the below things. Even i am able to get the connection successfully using this but getting some trouble and exception. I am explaining you all steps done by me-
*1. Have created a context.xml* I have put this context.xml in the META-INF folder of my application. but when i am deploying the web app to the server then it is not creating its copy to ${CATALINA-BASE}/conf/Catalina/locathost. Why is that so ? But when i am putting this context.xml in ${CATALINA-BASE}/conf folder then its working. <?xml version="1.0" encoding="UTF-8"?> <Context> <Resource name="jdbc/MaxDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="-1" username="root" password="root" driverClassName="com.mysql.jdbc.Driver" url="jdbc:MySQL://localhost:3306/MaxDB?zeroDateTimeBehavior=convertToNull"/> </Context> *2. Mapping in web.xml* <resource-ref> <description>MySql DataSource</description> <res-ref-name>jdbc/MaxDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> *3. Then on my servlet i am getting the object of connection like this-* private static InitialContext ic; protected static DataSource datasource; private static Context ctx; public void doSomeStuff() throws DatabaseException { Connection conn = null; try { conn= getConnection(); ..................................... // do the required stuff } catch (Exception ex) { } finally { conn.close(); } } *4. This is the method in my DAO Class i am using this method to get the object of connection at all of my servlet.* protected static Connection getConnection() throws DatabaseException { Connection conn = null; try { ctx = new InitialContext(); datasource = (DataSource) ctx.lookup("java:/comp/env/jdbc/MaxDB"); conn = datasource.getConnection(); } catch (Exception ex) { } return conn; } Using all this i am able to get connection. But if number of hits increases to the server and Initially i got the the below exception- *org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object* Then i got the exception- *org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))* Please assist me to know the root cause of the problem. I have searched it on google and have read lots of forum but did not get the satisfactory answer. Hope that you all are expert and your suggestion will be valuable for me. Thanking You! *Best Regards, * *Saurabh Sarasvat*