Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
com.mysql.jdbc.Driver not found with mysql connector in buildpath

I'm working on connecting MySQL database to a Java program. When I run my program I am getting this error

Class Not Found Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

for this line

try{ Class.forName("com.mysql.jdbc.Driver").newInstance();

So, what's the problem? I'm placing the connector in the project's file.. Is the correct or should it be in another location?

OS Windows XP, Eclipse 4.0, mysql connector 5.1.22

share|improve this question

marked as duplicate by Brian Roach, home, EJP, Reimeus, Linger Dec 31 '12 at 15:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3  
Where in projects file? –  Nambari Dec 31 '12 at 6:44
1  
Did you include it in the classpath? –  ntalbs Dec 31 '12 at 6:46
    
@Nambari project file is in D:/ –  user1929226 Dec 31 '12 at 6:46
    
@user1929226 Anywhere in the CLASSPATH. The question doesn't really make sense. –  EJP Dec 31 '12 at 7:47

5 Answers 5

up vote 2 down vote accepted

JAR file need to add to project class path.

First Right click on you Eclipse Project,  Project --> Build Path --> Configure Build Path. Under Libraries tab, click Add Jars or "Add External JARs".
share|improve this answer

You don't even need that line of code, any time in the last five years or so. Just delete it,

share|improve this answer

The jar file should be in your classpath. If you have created the project through an IDE, make sure you add the jar in your build path.

share|improve this answer
    
how can I jar the connector? –  user1929226 Dec 31 '12 at 6:55

You have to include the connector jar file in your project's build path. In eclipse project properties dialog, go to "Java Build Path" and add the jar file in "Libraries" tab

share|improve this answer

the jar should be included in your classpath. In your IDE, configure your build path and add the required jar in your libraries section.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.