最白目
最白目

Reputation: 3634

Not SQL Driver Found - but Driver JAR File is implemented

I connect to a database:

          void connectToDataBase(){


      dataManager_ref = new DataBaseConfigurationManager();

       try
       {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dataBase","root",""); 
            System.out.println("Connection successful");
        }
        catch (Exception e)
        {
            System.err.println("Got an exception! "); 
            System.err.println(e.getMessage()); 
        }
     }

I implemented a JAR File for the driver:

mysql-connector-java-5.1.17-bin.jar

and imported it into the servlet

import java.sql.DriverManager;

this isnt the first time I use this database (tho the first time with Java EE web). This time I get the following exception:

No suitable driver found for jdbc:mysql://localhost:3306/dataBase

The application is running on a glassfish server 3.1, can I even use a database on a mysql server here? Can somebody help please

thanks in advance, Daniel

Upvotes: 0

Views: 346

Answers (2)

Kris
Kris

Reputation: 8868

You can add a CLASSPATH variable in Environmental System variables, and set the path to your connector, path including name of connector.jar. Also mysql-connector-java-5.1.17-bin.jar is showing some incompatibilities in accessing. it gave me lots of errors, so i had to go bac to 5.0.x versions

Upvotes: 0

Mike Q
Mike Q

Reputation: 23219

You sometimes need to load the Driver class explicitly in order for the DriverManager to be aware of it.

Try this

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

Before you call the DriverManager

Upvotes: 2

Related Questions