Reputation: 3634
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
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
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