1

I am facing a mind boggling error when I try to connect JDBC from Java program in Eclipse as below:

public class DbAccess {
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://";
    private String userName;
    private String password;
    public Connection conn;
    public Statement stmt;

    public boolean dbLogin(String name, String passwd) {
        this.userName = name;
        this.password = passwd;
        String host = "localhost", dbschema = "s15g108"; 
        boolean connStatus = false;
        try {
            // Registering the JDBC Driver
            Class.forName(JDBC_DRIVER);
            try {

In the above code, I am getting an error as below when executing "Class.forName(JDBC_DRIVER); statement. enter image description here

I have placed the JAR file already in the Project build path as shown below:

enter image description here

The image below shows the snapshot of jar file being referenced for the project: enter image description here

Can you please help as what has gone wrong here? I am stuck at this error and not able to proceed at all.

3
  • Are you able to open the com.mysql.jdbc.Driver type? Is it actually in that jar? Is this the same project? Are the other two processes supposed to still be running (and potentially causing file locking issues)? Commented Mar 16, 2015 at 4:36
  • I am sorry, I am not able to interpret your questions. How to open the type? Yes, It's in the JAR. It's the same project for which I showed the snapshots. Which two processes you mean? Commented Mar 16, 2015 at 4:50
  • Could you edit your question to include the stacktrace for the ClassNotFoundException? It may have a "caused by" section which is relevant. Commented Mar 21, 2015 at 12:36

1 Answer 1

1

Build path is not the same thing as the runtime classpath. Try putting the MySQL jar in your project's lib directory.

Sign up to request clarification or add additional context in comments.

2 Comments

It is for a Java Application.
I have added a snapshot above to confirm that jar is in project lib directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.