anjali
anjali

Reputation: 77

JDBC connection driver issue in eclipse

I am working on jdbc connection and I am using eclipse. I have placed connection driver that is mysql-connector-java-5.1.6.jar file in WebContent/WEB-INF/lib folder. After that I am writing this code to simply create and test connection between application and driver

import java.lang.ClassNotFoundException;

    public class implementation {

        public static void main(String[]arg)
        {
            try
            {
                System.out.println("conneting to driver...");
                Class.forName("com.mysql.jdbc.driver");
                System.out.println("Connection Successful");

            }
            catch(ClassNotFoundException error)
            {
                System.out.println("Error:" + error.getMessage()); 
            }
        }

    }

when I am running this program, I am getting this error.

connecting to driver.

Error:com.mysql.jdbc.driver

can you please help to solve this issue. thank you for giving me your important time.

Upvotes: 1

Views: 1489

Answers (3)

Ram72119
Ram72119

Reputation: 107

Class.forName("com.mysql.jdbc.driver");

By typing driver name manually like above, we are getting ClassNotFoundException because of small spell mistakes

That's why always better to use when the fully qualified class name is the input for method

for example,

Class.forName(Driver.class.getName().toString());

Before this we need to set the mysql-version.jar file into the buid path

Upvotes: 0

vagabondtechie
vagabondtechie

Reputation: 223

You are getting ClassNotFoundException because the correct driver class name is com.mysql.jdbc.Driver and not com.mysql.jdbc.driver.

The 'D' of Driver is capital(standard Camel Case notation)

Hope this helps.

Upvotes: 2

PSR
PSR

Reputation: 40318

Add that jar file to BuildPath of the project.

Right Click on the project --> BuildPath -- Configure builaPath -->Add external jars.

Because You are not running a web application.

Upvotes: 0

Related Questions