开发者

Not SQL Driver Found - but Driver JAR File is implemented

开发者 https://www.devze.com 2023-03-30 05:30 出处:网络
I connect to a database: void connectToDataBase(){ dataManager_ref = new DataBaseConfigurationManager();

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消