Avatar of Kevin B
Kevin B
 asked on

Where to place postgres JDBC driver jar on tomcat

Hi, I have been getting an error in my java web application "No suitable driver found for jdbc:postgresql://...."

This is a maven java web application.  The jar is included as a dependency in the pom file and when the WAR is built out the jar can be found in webapps/MyApplication/WEB-INF/lib.  

I also tried placing the jar in /usr/share/tomcat/lib.  I am still recieving the same error.  I have tried this on a local DB with postgres and the driver works fine.  Can anyone help me out?
* JDBC* DriverJavaPostgreSQL* Tomcat

Avatar of undefined
Last Comment

8/22/2022 - Mon

Hi, I have been getting an error in my java web application "No suitable driver found for jdbc:postgresql://...."
Can you post the error as it is exactly please (maybe change the odd letter, but not the form) as it could be the url rather than driver placement
Kevin B

The error message is "No suitable driver found for jdbc:postgresql://"  I am connecting to this DB via pgadmin and it seems to work just fine with this IP address.
Kevin B

Here is my actual code
	private String getCustomersResults() throws SQLException {
		log.info("The customer results will be printed");
		String url = "jdbc:postgresql://";
		Properties props = new Properties();
		props.setProperty("user", "postgres");
		props.setProperty("password", "postgres");
		Connection conn = DriverManager.getConnection(url, props);
		Statement statement = conn.createStatement();
		log.info("select price from public.customer_rating");
		ResultSet rs = statement.executeQuery("select price from public.customer_rating");

		String price = "";
		while (rs.next()) {
			price = rs.getString("price");
		log.info("The price is " + price);
		return price;

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

How would your code know which driver class to use? You didn't tell it
Kevin B

My understanding was that the JDBC code will look for the driver in your build path.  I have a postgres driver.... is there a way to explicitly tell it?  Is this code not correct?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Kevin B

This fixed it.  Thanks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.