| | |
MySQL drivers not loading?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
Using the following:
I get the output
"Midway drivers are nada"
"null"
This tells me that java.security.AccessController.doPrivileged isn't quite doing what I expected. Why isn't it picking up a driver? Is it the proper usage? How /do/ you load a mySQL driver, anyways?
Other than the printlns, this is about the same as the mySQL code I had seen other places.
Thanks,
Java Syntax (Toggle Plain Text)
protected void testDriver ( ) { String drivers = "nada"; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch ( java.lang.ClassNotFoundException e ) { System.out.println("MySQL JDBC Driver not found ... "); } catch (IllegalAccessException ex) { System.out.println("Illegal Access"); } catch (InstantiationException ex) { System.out.println("Instantiation problem"); } System.out.println("Midway drivers are " + drivers); try { drivers = (String) java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("jdbc.drivers")); } catch (Exception ex) { drivers = "balderdash"; } System.out.println(drivers); }
I get the output
"Midway drivers are nada"
"null"
This tells me that java.security.AccessController.doPrivileged isn't quite doing what I expected. Why isn't it picking up a driver? Is it the proper usage? How /do/ you load a mySQL driver, anyways?
Other than the printlns, this is about the same as the mySQL code I had seen other places.
Thanks,
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by server_crash
Where are you making a connection to the DB?
This fellow wrote a two-step connection process; the first to just fire the Class.forName with the assumption that the driver was good, and then the next to see whether the user-input database host name was any good.
That didn't quite make sense to me either, so I just rewrote it:
Java Syntax (Toggle Plain Text)
public int DBtest( String hst ) { host = hst; String url = ""; // testDriver ( ); String drivers = "nada"; try { Class.forName("com.mysql.jdbc.Driver");//.newInstance() } catch ( java.lang.ClassNotFoundException e ) { System.out.println("MySQL JDBC Driver not found ... "); } /* System.out.println("Midway drivers are :" + drivers); try { drivers = (String) java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("jdbc.Driver")); } catch (Exception ex) { drivers = "balderdash"; } if (drivers == null) System.out.println("It really is NULL"); System.out.println("Ending drivers are :" + drivers); */ try { //url = "jdbc:mysql://" + host + "/" + database + "?user=" + username + "&password=" + password; url = "jdbc:mysql://" + host + "/" + database; Connection con = DriverManager.getConnection(url, "username", "password"); con.close(); return 1; } catch ( java.sql.SQLException e ) { System.out.println(e); return 0; } }
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by jwenting
JDBC drivers are usually dependent on specific versions of the database engine in use.
Find out what version of mySQL you're using and what driver you need for it.
Also tried adding
Java Syntax (Toggle Plain Text)
static { System.loadLibrary("msvcr71"); System.loadLibrary("myodbc3"); System.loadLibrary("myodbc3S"); }
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
Okay, a rundown:
Running in JBuilder 2005
Using the following: I get the following output:
list2 isn't empty So it found and loaded a driver...
com.mysql.jdbc.Driver@650646 Here it is...
Filler Here's a line I did to make sure I wasn't printing a blank list...
The exception is java.sql.SQLException: No suitable driver And I'm still getting this result.
If it's in the DriverManager, why wouldn't it connect? Is it just a bad driver (I wouldn't think so, it came with the same version as a working program) or is the driver not in the right place, or is there a process I'm missing somewhere?
Running in JBuilder 2005
Using the following:
Java Syntax (Toggle Plain Text)
try { java.sql.Driver mySQLDriver = (Driver) Class.forName("com.mysql.jdbc.Driver").newInstance(); DriverManager.registerDriver(mySQLDriver); }catch(Exception e){ e.printStackTrace(); } java.util.Enumeration driverlist = DriverManager.getDrivers(); if(!driverlist.hasMoreElements()){ System.out.println("If you see this than something is really screwed on this system..."); } try { Object Instants = Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch ( java.lang.ClassNotFoundException e ) { System.out.println("MySQL JDBC Driver not found ... "); } catch (IllegalAccessException ex) { System.out.println("Illegal Access"); } catch (InstantiationException ex) { System.out.println("Instantiation problem"); } java.util.Enumeration driverlist2 = DriverManager.getDrivers(); Object ob = null; if(driverlist2.hasMoreElements()) System.out.println("list2 isn't empty"); else System.out.println("list2 is empty"); for (; driverlist2.hasMoreElements(); ){ ob = driverlist2.nextElement(); System.out.println(ob); System.out.println("Filler"); } try{ Connection c = DriverManager.getConnection("jdbc:mysql://ycb","root","R00T"); c.close(); } catch ( java.sql.SQLException e) { System.out.println("The exception is " + e); }
list2 isn't empty So it found and loaded a driver...
com.mysql.jdbc.Driver@650646 Here it is...
Filler Here's a line I did to make sure I wasn't printing a blank list...
The exception is java.sql.SQLException: No suitable driver And I'm still getting this result.
If it's in the DriverManager, why wouldn't it connect? Is it just a bad driver (I wouldn't think so, it came with the same version as a working program) or is the driver not in the right place, or is there a process I'm missing somewhere?
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
Okay, trying yours but adding error catching and helpful printlns:
I get: Connection error; exception java.sql.SQLException: No suitable driver
Hmm... seeing if I can find what this error message means, since it's obvious I have a driver in there, and it's supposedly the one that belongs with the version MySQL I'm using.
Looks like most other people are having problems with how their url is formatted. Checking that out...
Java Syntax (Toggle Plain Text)
public int DBtest2(String hst){ int worked = 1; try{Class.forName("com.mysql.jdbc.Driver").newInstance();} catch(Exception e){System.out.println("Class Error; exception " + e); worked = 0;} String url = "jdbc:mysql://"+hst; try{Connection conn = DriverManager.getConnection(url, username, password); conn.close();} catch(Exception e){System.out.println("Connection error; exception " + e); worked = 0;} return worked; }
Hmm... seeing if I can find what this error message means, since it's obvious I have a driver in there, and it's supposedly the one that belongs with the version MySQL I'm using.
Looks like most other people are having problems with how their url is formatted. Checking that out...
•
•
Join Date: Jul 2005
Posts: 20
Reputation:
Solved Threads: 0
More fidgeting; after changing the connection's catch statement to:
I got:
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
Java Syntax (Toggle Plain Text)
catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); worked = 0; }
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
![]() |
Other Threads in the Java Forum
- Previous Thread: Time delay
- Next Thread: business online app/business graphic app
| Thread Tools | Search this Thread |
android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice dragging draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui hql html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






