tags:

views:

173

answers:

4

I'm assuming I need to use Connector\J and JDBC to achieve this, but I can't seem to 'install' Connector\J using the CLASSPATH thing. How do I do that ? I use the IntelliJ IDE if thats relevant.

I'm looking for a way to talk to a mysql database and execute and print out a few basic queries but I'm not getting anywhere because I can't even talk to the database.

Any help is appreciated.

+6  A: 

You might follow an example such as this one:

http://www.kitebird.com/articles/jdbc.html

But, you might want to consider using Hibernate unless you're doing only a couple basic queries.

Don Branson
+4  A: 

See Using MySQL with Java -- the first link from Google.

Bombe
What's going on here?
Bedwyr Humphreys
Rich B is eliminating all lmgtfy posts. I have no problem with that, but I'd like there to be at least *some* content (not that there was any to start with, but people did upvote some of those answers).
Michael Myers
Isn't it down to other users to downvote such answers rather than have RichB edit the answer into nonsense?
Bedwyr Humphreys
+1  A: 

Which version of IntelliJ?

You need to add the MySQL Connector-J JAR to your project dependencies.

Open your IntelliJ settings (the "wrench" in the top menu bar), go to "Libraries", click on "Attach Classes", and add the MySQL Connector-J JAR that you downloaded above. That puts it in your CLASSPATH.

If you still have problems, it means you don't have the driver class name right. It should be com.mysql.jdbc.Driver.

duffymo
+3  A: 

I like this tutorial because it's very detailed and thorough. Pretty much every step from downloading and installing MySQL and Connector/J to writing and running queries is covered.

Bill the Lizard