File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQLException: Driver not found for URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException: Driver not found for URL" Watch "SQLException: Driver not found for URL" New topic
Author

SQLException: Driver not found for URL

Darren Ziebart
Greenhorn

Joined: Sep 05, 2003
Posts: 3
Hi everyone,
I'm having some problems with JDBC and connecting to a mysql database on a Linux machine. I've downloaded the drivers (MySQL Connector-J) and have the jar file in my jre/lib/ext directory. Everytime I try and run it I get the following error:
Error with sql java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost/sw4

Here is the code in question.

String connectionURL = "jdbc:mysql://localhost/JobDB";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "username", "password") ;
ps = con.prepareStatement("SELECT clientID FROM clients");
rs = ps.executeQuery();
Something in the DriverManager is causing me too much grief.
Thanks in advance.
Darren Ziebart
Greenhorn

Joined: Sep 05, 2003
Posts: 3
Sorry, forgot to include a print out of the stack trace.

Error with sql java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost/JobDB
java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost/JobDB
at 0x4028115f: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/libgcj.so.3)
at 0x402740d2: java.lang.Exception.Exception(java.lang.String) (/usr/lib/libgcj.so.3)
at 0x40316294: java.sql.SQLException.SQLException(java.lang.String, java.lang.String, int) (/usr/lib/libgcj.so.3)
at 0x40316244: java.sql.SQLException.SQLException(java.lang.String) (/usr/lib/libgcj.so.3)
at 0x40316102: java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.3)
at 0x4031603a: java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, java.lang.String) (/usr/lib/libgcj.so.3)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3)
at 0x4039d307: ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3)
at 0x4039d307: ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3)
at 0x4039d307: ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3)
at 0x4039d307: ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0)
at 0x40267fdc: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.3)
at 0x4038c220: ?? (??:0)
at 0x40393ce5: GC_start_routine (/usr/lib/libgcj.so.3)
at 0x4061c941: ?? (??:0)
at 0x420da1ca: ?? (??:0)
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
You don't put libraries in your lib/ext, you put them in your classpath.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Except that the MySQL Connector/J documentation explicitly says to put the driver jar file in jre/lib/ext .


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Darren,
Welcome to JavaRanch!
(Just shooting in the dark...)
What kind of app are you trying to implement? It's not a web app is it?
As you're including the JAR in your ext directory, this may be a non-issue - I don't presently recall. I'm just pointing out that an application server (such as Tomcat) is going to ignore the CLASSPATH setting, and just use libraries in the shared or in the web app's lib directory. Of course, this might not apply with libraries in the ext directory.
Otherwise, is it possible that a different version of Java is actually running than the one you've intended to run?
And is it possible that the JAR you have is somehow bad? Have you tried to download it again?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Darren Ziebart
Greenhorn

Joined: Sep 05, 2003
Posts: 3
Thanks for all the advice. It turns out that there was a non-sun version of Java previously installed on the server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLException: Driver not found for URL
 
Similar Threads
Query about Connection interface
Java won't send SQL query
Only for one data in the text box
JSP: Unable to connect to mysql in local drive [Solved]
Properties file for DB connection