File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connecting to MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connecting to MySQL" Watch "Connecting to MySQL" New topic

Connecting to MySQL

Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Hello Everyone,

I am quite new in using JDBC, I know this question is repeated but as i couldn't solve problem so writing you for help.

I am running this program in eclipse with Windows vista and MySQL and receiving this error "Cannot connect to database serverjava.lang.ClassNotFoundException: com.mysql.jdbc.Driver"

I copied all extracted file of "mysql-connector-java-5.1.6" in MySQLDB package and also tried by setting the classpath but always get error.

I'll be very thankful to you for help in this regard.
[ August 14, 2008: Message edited by: Tahir Abbas ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

Is this a standalone Java program in Eclipse? If so, can you confirm the mysql jar is in your project's build path. If not, what server are you using?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Thanks! for help, yea problem was in build path i am writing steps may be helpful for someone else.

1- After opening project window(menu) > Preference then select Java>build Path > classpath variable and click on new button and give variable name and path of unzipped mysql connector folder in the appeared dialogue box, click ok again ok.

2- Right click on Project Properties select Java Build Path then click on Libraries tab then click on classpath variable. Select the newly formed variable from the list then click on Extend button ___.jar file will appear click on jar file then click ok, ok.

This way i got right output.

Thanks! for help and Regards
I agree. Here's the link:
subject: Connecting to MySQL
jQuery in Action, 3rd edition