I\'m trying to add a database-enabled JSP to an existing Tomcat 5.5 application (GeoServer 2.0.0, if that helps).
The app itself talks to Postgres just fine, so I kn
No matter how old this thread becomes, people would continue to face this issue.
My Case: I have the latest (at the time of posting) OpenJDK and maven setup. I had tried all methods given above, with/out maven and even solutions on sister posts on StackOverflow. I am not using any IDE or anything else, running from bare CLI to demonstrate only the core logic.
Here's what finally worked.
Class.forName(....)
. The file that we want is the com/mysql/jdbc/Driver.class
javac App.java
java --module-path com/mysql/jdbc -cp ./ App
This would load the (extracted) package manually, and your java program would find the required Driver class.
mysql
driver, other drivers might require minor changes..deb
image, you can get the jar from /usr/share/java/your-vendor-file-here.jar
I encountered this issue by putting a XML file into the src/main/resources
wrongly, I deleted it and then all back to normal.
The infamous java.sql.SQLException: No suitable driver found
This exception can have basically two causes:
You need to ensure that the JDBC driver is placed in server's own /lib
folder.
Or, when you're actually not using a server-managed connection pool data source, but are manually fiddling around with DriverManager#getConnection()
in WAR, then you need to place the JDBC driver in WAR's /WEB-INF/lib
and perform ..
Class.forName("com.example.jdbc.Driver");
.. in your code before the first DriverManager#getConnection()
call whereby you make sure that you do not swallow/ignore any ClassNotFoundException
which can be thrown by it and continue the code flow as if nothing exceptional happened. See also Where do I have to place the JDBC driver for Tomcat's connection pool?
You need to ensure that the JDBC URL is conform the JDBC driver documentation and keep in mind that it's usually case sensitive. When the JDBC URL does not return true
for Driver#acceptsURL() for any of the loaded drivers, then you will also get exactly this exception.
In case of PostgreSQL it is documented here.
With JDBC, a database is represented by a URL (Uniform Resource Locator). With PostgreSQL™, this takes one of the following forms:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database
In case of MySQL it is documented here.
The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets (
[ ]
) being optional:
jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] » [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
In case of Oracle it is documented here.
There are 2 URL syntax, old syntax which will only work with SID and the new one with Oracle service name.
Old syntax
jdbc:oracle:thin:@[HOST][:PORT]:SID
New syntax
jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE
It might be worth noting that this can also occur when Windows blocks downloads that it considers to be unsafe. This can be addressed by right-clicking the jar file (such as ojdbc7.jar), and checking the 'Unblock' box at the bottom.
Windows JAR File Properties Dialog: