Where to place postgres JDBC driver jar on tomcat

Kevin B
Kevin B used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
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

Author

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

Author

Commented:
Here is my actual code
	private String getCustomersResults() throws SQLException {
		log.info("The customer results will be printed");
		String url = "jdbc:postgresql://10.233.1.40:5432/postgres";
		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);
		rs.close();
		conn.close();
		return price;
	}

Open in new window

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Top Expert 2016

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

Author

Commented:
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?
Top Expert 2016
Commented:
My understanding was that the JDBC code will look for the driver in your build path
No, code to run isn't interested in the build path ;)
Check out the docs for DriverManager. The driver class needs to be a property as well

Author

Commented:
This fixed it.  Thanks
Top Expert 2016

Commented:
:)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial