Forums Register Login

MySQL drivers

+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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".
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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...

+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Linking to Tim's comments for clarity. (You are correct that the question is different enough to warrant a new post.)
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
Beware the other head of science - it bites! Nibble on this message:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1755 times.
Similar Threads
JDBC drivers/getting JDBC started
another JDBC driver question
Connection to MySql Database
need help on dynamic loading of jdbc driver
more then one Drivers at once
ResultSet object returning null
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:29:00.