• 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

Setting up JDBC with MySQL

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!
Sorry to bother, but I've searched, and attempted, and failed at setting this up, and it's kind of frustrating.
Is there someone out there who might be able to tell me how to get the MySQL JDBC drivers to work? I have my classpath set to:
c:\java\bin;C:\jdbc\mysql-connector-java-2.0.14-bin.jar
This includes the java path, and also the path to MySQL Connector/J. I'm new to JDBC, obviously, but I keep getting the "No Suitable Driver" Exception.
Any and all help is GREATLY appreciated )
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we could see your code where you are trying to establish the connection...
Also, when you say that is your classpath, where did you set that classpath?
At runtime? -- java -classpath....
Environment Variables?
 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, for some reason it's working now. Here's the code that I used to make it work:

Problem now is, I have NO idea why it's working. Maybe it's because before I wasn't using Class.forName().newInstance(); at all.
Does that sound like the culprit?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not using Class.forName was exactly your problem. That is what actually loads the Driver for that DriverManager (among others) uses to access your Database. The Driver is what converts your JAVA instructions into instructions that a DBMS can understand. Kind of like a Gateway.
Good job trouble shooting!
 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So even if you set the enviro var, you still have to load the driver with Class.forName() for the DriverManager, huh?
Okay, I get it now (I think). I'll keep plugging at it, but thanks for the help! )
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classpath tells both the java compiler and the VM where to find additional API's/Libraries, whatever you want to call them.
When you put your Connector/J Driver in your classpath, all that did was add another search path so that when the compiler or the VM needs these libraries, it knows where to find them.
What JDBC does is use Reflection to load the Driver. That basically means that the Connector/J Driver.class file get's loaded and compiled on the fly, or at runtime instead of at compile time. I don't know why they did it this way.
It's just like with the standard API set. Just because they are available via the classpath doesn't mean they are being used.
So as you have probably infered, you not only need the Driver in your classpath so java can find it, but you also need to load it.
In fact, you only need the Connector/J Driver in your classpath when you are executing the code, not when compiling, because it compiles the driver at runtime. However, I have it in my classpath for both compile and execution. Just in case.
Here is a link to a tutorial I have started on the very basics of JDBC. I basically simplified the very simple JDBC Tutorial from Sun.
But it hits on a few details that Sun thought most people would infer. I however didn't so I though I would help others like me.
[ December 11, 2002: Message edited by: Gregg Bolinger ]
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gregg, the type 4 is also named III - what's up with that
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Fixed.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic