• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQLException: Driver not found for URL

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't put libraries in your lib/ext, you put them in your classpath.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except that the MySQL Connector/J documentation explicitly says to put the driver jar file in jre/lib/ext .
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Darren Ziebart
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the advice. It turns out that there was a non-sun version of Java previously installed on the server.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic