• 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

How do I load 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
I'm having a problem loading a mysql driver, but it was suggested the problem more likely lay in my environment (JBuilder Foundation 2005) than the code.

With the following I ended up getting:
"list2 isn't empty
null
The exception is java.sql.SQLException: No suitable driver"
So I'm loading successfully, for some reason my driverlist has something in it, but ends up printing null when I try to access it.

The only thing I can reason out of this is that I'm loading a null object into the driverlist, and that's what's printing out.

Does anyone have familiarity with loading MySQL drivers in a JBuilder environment?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"no suitable driver" means that the driver class(es) (jar) isn't in your classpath.

Your enumeration is wrong. The "nextElement" won't be done until the body of the loop (the System.out.println(obj)) has already executed.

try:
 
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 Tim Holloway:
"no suitable driver" means that the driver class(es) (jar) isn't in your classpath.


Hm. All the examples I've seen about adding things to classpaths ends up clobbering the line in the way it executes. Is there a graceful way to find out what the existing classpath is, and put the appropriate driver into the directory in the current classpath?


Your enumeration is wrong. The "nextElement" won't be done until the body of the loop (the System.out.println(obj)) has already executed.


Ahh, fenceposts. Okay, JBuilder didn't quite like yours with the fact that ob was getting something inside the loop when it was instantiated in the condition statement. Lemme see about rewriting that a little bit...


Plus the previous bit with the attempted connection.
Okay, with this I'm getting:
list2 isn't empty //So the drivermanager is finding the driver in question
com.mysql.jdbc.Driver@650646 //And here it is
Filler //I put this line in just to make sure it wasn't printing blank lines
The exception is java.sql.SQLException: No suitable driver //Still getting this.

So it's showing up in driverManager, it just doesn't like it. Hmm... is this still an IDE question? Lots of bouncing with this one...
 
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
Since we've verified that it is in fact getting a driver, I've made a much shorter driver-testing method... pretty much cut-and-paste from the MySQL reference manual:

Which comes back with:
SQLException: No suitable driver
SQLState: 08001
VendorError: 0

Seeing if I can find where the error codes come from...
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, I missed your previous post, and it seems this has been a problem for a while.

To list your classpath:

System.out.println("Java Classpath=" + System.getProperty("java.class.path"));

should do it.

Normally, I can get by with just a



Which seems to be the way they did it here.

It's my day to be senile, so I forget when using the Register Driver function is a prerequisite. Older JDBC drivers needed the newInstance() on Class.forName(), but I think that's no longer true. In any event, I never ran into problems using the MySQL driver.
 
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
Well, bother. With that, it looks like the current classpath is:

But when I look at the jbuilder.config file, it has, "addjars ../lib", and the "mysql-connector-java-3.0.8-stable-bin" jar file is definitely in the JBuilder lib folder. Waitaminute, missing a step... JBuilder/lib not quite the same as the Jbuilder/jdk1.4/lib folder... this might be it... dag. Well, now I feel silly, the JBuilder has a 'Classpath display'.

No such luck. I copied "mysql-connector-java-3.0.8-stable-bin" into JBuilder/jdk1.4/lib where plugin.jar, htmlconverter.jar, etc. are sitting, exited from JBuilder, started it again, and it's listing the same classpath as above without "mysql-connector" in the list. In case the name was confusing JBuilder, I copied it and named it simply "mysql", but that's not showing up in the classpath either.

Which leaves me with two questions:
1) If jdk1.4/lib is in the addjars list, and "mysql*.jar" are in jdk1.4/lib, why aren't they showing up in the classpath?
2) If "mysql*.jar" isn't in the classpath, then what's that thing in the driver list?
3) For people with functioning mysql examples, if you do a driverlist, what do yours look like?
Will see what I can find out... check back with y'all on my progress, or see if anyone else has found answers.
Thanks,
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I'm out of my depth here. I haven't used JBuilder in way too long to suggest anything on JBuilder-specific problems.

Only thing I can suggest is to note that both IntelliJ and Eclipse posess a "Project Properties" (or Module Properties) menu option that's used as a reference for things like what jars are used to build and test a project - also you may be able to define a class path for a Run/Debug profile.

I'd look for a JBuilder equivalent. Often, to prevent Version Hell, I copy the driver jar into the "lib" directory of the project and set up a project-local library definition, but for framework-based apps I may refer to a master copy, such as one I've placed in my in TOMCAT_HOME/server/common/lib. The setup and display of project-local vs. external jars may be different, but the net effect when it comes run time is the same.
 
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
Sacre bleu... okay, so I made a test program to see what the problem was.
Behaves surprisingly well; all it does is "Starting!" and "Ending!"
Conversely, with inside the program that's trying to use it, I'm still getting the aforementioned error messages.

So, is there a difference between how they're applied? Does JBuilder react differently if a ForName call is made inside a void vs. int method?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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:
So, is there a difference between how they're applied? Does JBuilder react differently if a ForName call is made inside a void vs. int method?



No. Class.forName() is just a static method of the Class class that invokes its classloaders to find a class definition for the class whose fully-qualified name matches the argument passed to it. I use that in my World-Famous EJBWizard [TM] utility to dynamically load classes so that I can then create a plugin object by using the newInstance() method on the returned class to invoke the plugin class's no-argument constructor.

Many Java IDEs are written in Java, so often they can be passed a CLASSPATH when started. However, the CLASSPATH needed to run/debug an app WITHIN the IDE may be very different from the CLASSPATH needed by the IDE itself. Which is why I recommended checking for a project classpath settings option. These settings will be used to setup the JVM under which the app test will run.
 
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
Hmm again. I'm not sure the connection difference has to do with running inside or out of the environment, since I'm running both the connecting test-sql and the non-connecting ycb inside JBuilder.
Also, they both have C:\Program Files\Ycb2.4\Code\src\mysql-connector-java-3.1.8\mysql-connector-java-3.1.8-bin.jar; in their listed Classpaths (which is also odd considering they're separate projects).
Not sure when the mysql-connector line got added, it wasn't there when I searched on *sql* earlier.

Let me add a little to the test program to make sure it's actually connecting.
Yep, successfully added a line to the database.

And if anyone reads this in the time we have left, Happy New Year! Well, I guess it applies afterwards as well...
 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic