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?
Kevin BAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
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
0
Kevin BAuthor 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.
0
Kevin BAuthor 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

0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

CEHJCommented:
How would your code know which driver class to use? You didn't tell it
0
Kevin BAuthor 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?
0
CEHJCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kevin BAuthor Commented:
This fixed it.  Thanks
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JDBC

From novice to tech pro — start learning today.