It shows error as "No suitable driver"
You apparently did System.out.println(e.getMessage())
instead of a e.printStackTrace()
. Then you will indeed get that little information. But this message is recognizeable as being a SQLException
which can basically have two causes:
- The driver is not loaded.
- The (wrong) JDBC URL didn't return
true
for Driver#acceptsURL()
for any of the loaded drivers.
To fix 1, you need to ensure that you have a
Class.forName("com.example.jdbc.Driver");
in your code prior to DriverManager#getConnection()
call and that you do not swallow/ignore any ClassNotFoundException
which can be thrown by it by putting for example an empty catch block or just doing a System.out.println()
instead of throwing it.
To fix 2, you need to ensure that the JDBC URL syntax conforms the one as specified in the JDBC driver documentation. In case of Oracle it is located here. Here's a quote:
In JDBC all url's begin with jdbc:protocol: This is the standard. After this is driver specific, and no two drivers are the same.
What is the form of a URL?
The general form of a URL is
jdbc:oracle:<drivertype>:<username/password>@<database>
The <drivertype>
is one of
The <username/password>
is either empty or of the form <username>/<password>
In your specific case, the URL looks okay, so you might have not loaded the right driver or plain ignored the ClassNotFoundException
thrown by it.