MySQL drivers not loading?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

MySQL drivers not loading?

 
0
  #1
Nov 7th, 2005
Using the following:
  1. protected void testDriver ( ) {
  2. String drivers = "nada";
  3. try {
  4. Class.forName("com.mysql.jdbc.Driver").newInstance();
  5. } catch ( java.lang.ClassNotFoundException e ) {
  6. System.out.println("MySQL JDBC Driver not found ... ");
  7. } catch (IllegalAccessException ex) {
  8. System.out.println("Illegal Access");
  9. } catch (InstantiationException ex) {
  10. System.out.println("Instantiation problem");
  11. }
  12. System.out.println("Midway drivers are " + drivers);
  13. try {
  14. drivers = (String) java.security.AccessController.doPrivileged(
  15. new sun.security.action.GetPropertyAction("jdbc.drivers"));
  16. } catch (Exception ex) {
  17. drivers = "balderdash";
  18. }
  19. System.out.println(drivers);
  20. }

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,
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: MySQL drivers not loading?

 
0
  #2
Nov 7th, 2005
Where are you making a connection to the DB?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

Re: MySQL drivers not loading?

 
0
  #3
Nov 7th, 2005
Originally Posted by server_crash
Where are you making a connection to the DB?
Hello Wizard!
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:
  1. public int DBtest( String hst ) {
  2.  
  3. host = hst;
  4. String url = "";
  5.  
  6. // testDriver ( );
  7. String drivers = "nada";
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");//.newInstance()
  10. } catch ( java.lang.ClassNotFoundException e ) {
  11. System.out.println("MySQL JDBC Driver not found ... ");
  12. }
  13. /* System.out.println("Midway drivers are :" + drivers);
  14.   try {
  15.   drivers = (String) java.security.AccessController.doPrivileged(
  16.   new sun.security.action.GetPropertyAction("jdbc.Driver"));
  17.   } catch (Exception ex) {
  18.   drivers = "balderdash";
  19.   }
  20.   if (drivers == null) System.out.println("It really is NULL");
  21.   System.out.println("Ending drivers are :" + drivers);
  22. */
  23. try {
  24. //url = "jdbc:mysql://" + host + "/" + database + "?user=" + username + "&password=" + password;
  25. url = "jdbc:mysql://" + host + "/" + database;
  26. Connection con = DriverManager.getConnection(url, "username", "password");
  27. con.close();
  28. return 1;
  29. } catch ( java.sql.SQLException e ) {
  30. System.out.println(e);
  31. return 0;
  32. }
  33. }
For whatever reason, GetPropertyAction really was returning NULL, even though Class.forName() isn't throwing the "Not Found" error. Anyway, the only output now is, "java.sql.SQLException: No suitable driver". It's possible that MySQL has changed drastically since the previous guy was programming on this, but I was hoping the same drivers were still valid.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: MySQL drivers not loading?

 
0
  #4
Nov 8th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

Re: MySQL drivers not loading?

 
0
  #5
Nov 8th, 2005
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.
All right... I just downloaded MySQL 5, and the project's running on MySQL 4.0.14, and they both claim to be able to use driver 3.51. Unfortunately, after installing the 3.51 driver, the program is still saying, "No suitable driver."

Also tried adding
  1. static {
  2. System.loadLibrary("msvcr71");
  3. System.loadLibrary("myodbc3");
  4. System.loadLibrary("myodbc3S");
  5. }
, which corresponds with the three dlls that came with the 3.51 version, but still no dice. Strangely, I couldn't find a "driver.class" or "driver.java" file in the downloads.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

Re: MySQL drivers not loading?

 
0
  #6
Nov 18th, 2005
Okay, a rundown:
Running in JBuilder 2005
Using the following:
  1. try {
  2. java.sql.Driver mySQLDriver = (Driver) Class.forName("com.mysql.jdbc.Driver").newInstance();
  3. DriverManager.registerDriver(mySQLDriver);
  4. }catch(Exception e){
  5. e.printStackTrace();
  6. }
  7. java.util.Enumeration driverlist = DriverManager.getDrivers();
  8. if(!driverlist.hasMoreElements()){
  9. System.out.println("If you see this than something is really screwed on this system...");
  10. }
  11.  
  12. try {
  13. Object Instants = Class.forName("com.mysql.jdbc.Driver").newInstance();
  14. } catch ( java.lang.ClassNotFoundException e ) {
  15. System.out.println("MySQL JDBC Driver not found ... ");
  16. } catch (IllegalAccessException ex) {
  17. System.out.println("Illegal Access");
  18. } catch (InstantiationException ex) {
  19. System.out.println("Instantiation problem");
  20. }
  21. java.util.Enumeration driverlist2 = DriverManager.getDrivers();
  22. Object ob = null;
  23. if(driverlist2.hasMoreElements()) System.out.println("list2 isn't empty");
  24. else System.out.println("list2 is empty");
  25. for (; driverlist2.hasMoreElements(); ){
  26. ob = driverlist2.nextElement();
  27. System.out.println(ob);
  28. System.out.println("Filler");
  29. }
  30. try{
  31. Connection c = DriverManager.getConnection("jdbc:mysql://ycb","root","R00T");
  32. c.close();
  33. } catch ( java.sql.SQLException e) {
  34. System.out.println("The exception is " + e);
  35. }
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 765
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: MySQL drivers not loading?

 
0
  #7
Nov 26th, 2005
You'll get that error if it doesn't connect to the DB, has nothing to do with not finding the Driver.
This is all I have to connect to my DB:

Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://"+host;
connection = DriverManager.getConnection(url, user, password);
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

Re: MySQL drivers not loading?

 
0
  #8
Dec 3rd, 2005
Okay, trying yours but adding error catching and helpful printlns:
  1. public int DBtest2(String hst){
  2. int worked = 1;
  3. try{Class.forName("com.mysql.jdbc.Driver").newInstance();}
  4. catch(Exception e){System.out.println("Class Error; exception " + e); worked = 0;}
  5. String url = "jdbc:mysql://"+hst;
  6. try{Connection conn = DriverManager.getConnection(url, username, password); conn.close();}
  7. catch(Exception e){System.out.println("Connection error; exception " + e); worked = 0;}
  8. return worked;
  9. }
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: MonkeyCode is an unknown quantity at this point 
Solved Threads: 0
MonkeyCode MonkeyCode is offline Offline
Newbie Poster

Re: MySQL drivers not loading?

 
0
  #9
Dec 3rd, 2005
More fidgeting; after changing the connection's catch statement to:
  1. catch (SQLException ex) {
  2. // handle any errors
  3. System.out.println("SQLException: " + ex.getMessage());
  4. System.out.println("SQLState: " + ex.getSQLState());
  5. System.out.println("VendorError: " + ex.getErrorCode());
  6. worked = 0;
  7. }
I got:
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 765
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: MySQL drivers not loading?

 
0
  #10
Dec 4th, 2005
what does your full host address look like? If you dont specify a database, it must end with a "/".

jdbc:mysql://localhost/
or
jdbc:mysql://localhost/myDB

If that syntax isn't exact, you can get that "no driver" error.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC