Emil Grigore
Emil Grigore

Reputation: 949

Java can't connect to mysql database

I want to connect a server to a mysql database.I included the driver library mysql-connector-java-5.0.8.I installed the mysql connector.I have this code:

    public void connect() throws SQLException, ClassNotFoundException{

       String source="jdbc:derby://localhost:3306/security";
       Class.forName("com.mysql.jdbc.Driver");
       Connection con=DriverManager.getConnection(source,"root","");

} I use xampp for the mysql database.I made a database called security.When i try to execute the connect() method I receive the

     No suitable driver found for jdbc:derby://localhost:3306/security

exception.I searched for hours but I could not find a solution to my problem.This is the entire code I used to try to connect to the database.

Upvotes: 0

Views: 169

Answers (2)

sdanzig
sdanzig

Reputation: 4500

Try replacing "derby" with "mysql".

Upvotes: 2

Prabhakaran Ramaswamy
Prabhakaran Ramaswamy

Reputation: 26094

Replace

String source="jdbc:derby://localhost:3306/security";

to

String source="jdbc:mysql://localhost:3306/security";

Upvotes: 2

Related Questions