• 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

MySQL drivers

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Thanks,
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you trying to do with that and why? Do you want to iterate through a list of known drivers? There is an easy way to do this with DriverManager.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really, I'd just be happy to connect to a MySQL database. The previous programmer made two steps on this, for some reason. I combined them into one:

And now I'm getting "java.sql.SQLException: No suitable driver". Tried installing the 3.51 listed on MySQL AB as being compatible with my version of SQL, but it's still not recognizing. Also tried specifically requesting the dlls included in the install:

, but no such luck. Oddly, I couldn't find a "driver.class" or "driver.java" file anywhere in the 3.51 download.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. You seem to be sort of flailing around grasping at straws here so let's just review how to load and use the driver.

1) Load the driver using Class.forName If this steps works then you don't need to be loading anything else or worrying about your classpath etc.

From what you posted that seems to be working. Unless you are also getting a ClassDefNotFound Exception that you haven't posted.

2) Get a connection from the DriverManager using a URL. There are many things that go wrong at this stage. Your posted error "No Suitable Driver" means that no driver recognized the URL you sent along.

Again if you are not having a problem loading your driver then this means that your URL is incorrect.

After you load your driver could you try the following line

Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/badname?user=user&password=password");

And just tell us what error message you get with that? If your error is a MYSQL variety than the replace the host, database and user and password strings with your own and it should work.

If you get another general SQL error please post what it says.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Definitely grasping at straws... would help if I had written this in the first place rather than trying to come after someone else to sweep up.

I don't think ClassDefNotFound is thrown by Class.forName(). java.lang.ClassNotFoundException e is accounted for, I have a catch for it, and since the error statement I wrote in there isn't printing, I'm assuming it's not happening.

Logical progression is a very nice thing for programming brains. if(driverFound AND error) then (incorrectURL)
Lessee how your suggestions work out...
added... running...
two "java.sql.SQLException: No suitable driver"s. (one from yours, one from mine)

Also tried changing your suggested statement to:

since I thought there might be a problem with which getConnection I was using, but there's still "No suitable drivers".
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zachary Anderson:
Definitely grasping at straws... would help if I had written this in the first place rather than trying to come after someone else to sweep up.

I don't think ClassDefNotFound is thrown by Class.forName(). java.lang.ClassNotFoundException e is accounted for, I have a catch for it, and since the error statement I wrote in there isn't printing, I'm assuming it's not happening.

Logical progression is a very nice thing for programming brains. if(driverFound AND error) then (incorrectURL)
Lessee how your suggestions work out...
added... running...
two "java.sql.SQLException: No suitable driver"s. (one from yours, one from mine)

Also tried changing your suggested statement to:

since I thought there might be a problem with which getConnection I was using, but there's still "No suitable drivers".



That url still looks wrong. Where is the // after mysql?

But failing that the driver is not loading. If you are absolutley sure the driver is loading then can you uncomment the newInstance() bit? That was a workaround for an old problem on a few environments but let's just make sure the driver is registering itself.

If all that fails then I think it's time to isolate the problem by getting the list of drivers from the DriverManager after you have loaded the MySQL driver.

You can do that with DriverManager.getDrivers and just call toString on each one. Then you will know the following.

1) Either it is not there and therefore the driver loading is failing

or

2) The driver is loaded and your URL has some problem.

I am leaning towards 1 currently but it's hard to say for sure.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 � Tried "jdbc:mysql://mydatabase", same result.
2 � Switched to: , none of those exceptions are happening, still getting �No suitable driver.�
3 � Just below the updated �try Class.forName catch� statement, added which replied, �list is empty�. Does this mean I�m not loading it right, or do I not understand the Enumeration class?
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is a puzzler. If the driver list is empty then the driver is not being loaded and registered with the DriverManager and that is very odd.

Sorry I don't have a lot of time right now but as a next suggestion do the following.

Explictly load the driver and create an instance of it like you are doing. Cast the instance to java.sql.Driver. Then explictly register the driver with the DriverManager. That just has to work. If it doesn't then hopefully it will show us the real issue. I am beginning to suspect something is fishy with your runtime because this is not a problem I have ever seen before and it really is strange behaviour.

Anyway the code you should try is this...

 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More weirdness.
Sorry, forgot to mention; I'm running this on JBuilder 2005 (yay color-coded text, error checking, and filling in the blanks!). Do you think that's messing with the way it's loading the drivers?
Okay, I added your section near the beginning of the DBtest method, and changed my parts from driverlist to driverlist2. Here's what I got:
:list2 isn't empty (*your statement didn't print out, so hopefully that means my system isn't completely fudge... also saying there is actually something in list2 this time.)
:null (*unfortunately, list2.nextElement() seems to be null)
:The exception is java.sql.SQLException: No suitable driver (*same old song)
:java.sql.SQLException: No suitable driver (*and again)
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm yes that was worth mentioning. You running in the IDE too I suppose? This sounds like some sort of classpath in the IDE shenanigans and sorry but I don't know how to help you out. Other than to say consult the docs for the IDE... or maybe ask a question about setting up your classpath in your specific IDE in another forum (not another site just not the JDBC forum).

Sorry. I don't know. If you want to try running from a shell of some sort I can help you there. I have a feeling this will all suddenly start working though when you do which doesn't really solve your IDE configuration issue.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bother, showing more lack of experience here... not sure what IDE is. Running it from the JBuilder environment. Not entirely sure how classpaths work. I had a previous problem which was fixed when I copied the appropriate DLLs into the Borland/bin folder.

When I try running it from the windows dos-like cmd window, the program doesn't even start...
noclassdeffound for y class, which has the main and most definitely declares y. Rar. Okay, I'll see if anyone else knows about driver classpaths for Borland.
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Zachary,
IDE = Integrated Development Environment. So JBuilder is your IDE.

We have a forum further down on the page if you want to ask any questions about classpaths in JBuilder.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks much for the hunting help. Looks like I'm going to have to redirect the question. Given the output, the only thing I can assume is that something's being loaded in the driver list, but the thing is a null object.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zachary Anderson:
Thanks much for the hunting help. Looks like I'm going to have to redirect the question. Given the output, the only thing I can assume is that something's being loaded in the driver list, but the thing is a null object.



Not sure if anyone's still following this, but just to be sure... Tim Holloway pointed out that my loop for listing drivers skipped a step. After a small rewrite, it's listing "com.mysql.jdbc.Driver@650646" as the loaded driver in DriverManager. Still doesn't like it, though.
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Linking to Tim's comments for clarity. (You are correct that the question is different enough to warrant a new post.)
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, just to be clear...
Are you saying that the other thread is the new post, or the addition to this one is the new post, or I should make a new post somewhere in the Java -> Classpaths board?
A mite dense, I know.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zachary Anderson:
Sorry, just to be clear...
Are you saying that the other thread is the new post, or the addition to this one is the new post, or I should make a new post somewhere in the Java -> Classpaths board?
A mite dense, I know.



To be perfectly honest I don't know what to say about this one anymore. If the driver is loading and the URL is correct then the problem must be something when you are running in debug mode or something.

I would take this back into the IDE thread and say that the URL is correct (again assuming you are using the exact one I gave you because while that would give you a connection error (because the info is bogus) it is the correct protocol for the driver so you should not be getting a not suitable driver error).

I have not encountered this problem before but again I suspect something is going on in your IDE (JBuilder) so I would continue in that thread.
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zachary Anderson:
Sorry, just to be clear...
Are you saying that the other thread is the new post, or the addition to this one is the new post, or I should make a new post somewhere in the Java -> Classpaths board?
A mite dense, I know.


The other (IDEs) thread is the new thread. I was just linking to it so anyone who sees this thread can find it more easily.

It's not dense at all. It takes a little while to get used to all the forums.
reply
    Bookmark Topic Watch Topic
  • New Topic