4

I am using the sample code found here to implement Connection Pooling for my webapp: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Plain_Ol'_Java

Since I am using PostgreSQL as my database, I changed the line which says p.setDriverClassName("com.mysql.jdbc.Driver"); to p.setDriverClassName("org.postgresql.Driver");.

All I get is a ClassNotFoundException. Where have I gone wrong? Is there any other way?

EDIT: If I don't use connection pooling and do the normal way, I don't get the error.

EDIT 2: This isn't a duplicate of the suggested question. I am using Eclipse and have the jar included in Build Path and Deployment Assembly. As I said, the error doesn't come when NOT doing connection pooling and just manually opening the connection and closing.

4
  • Have you added the PostgreSQL libraries to your project/classpath/buildpath? Commented Nov 3, 2013 at 12:35
  • Yes I have. If I don't use connection pooling and do it normally, I don't get the error. Commented Nov 3, 2013 at 12:36
  • possible duplicate of ClassNotFoundException with PostgreSQL and JDBC Commented Nov 3, 2013 at 12:38
  • No, this isn't. Please see the updated question. Also, I am using Eclipse and have the jar included in Build Path and Deployment Assembly. As I said, the error doesn't come when NOT doing connection pooling. Commented Nov 3, 2013 at 12:41

1 Answer 1

5

Tomcat 7 expects to find JDBC driver JARs in its /lib folder. If you put them in your context WEB-INF/lib folder it won't find them and you'll get the error.

The reason it "works" when you don't do connection pooling is that the context class loader can find the JAR. Tomcat will only go as far as the app server class loader when it's involved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.