Reputation: 3013
try
{
String userName = "root";
String password = "";
//<facility> is my database
String url = "jdbc:mysql://localhost/facility";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.out.println ("Cannot connect to database server " +e.getClass().getName());
}
output> Cannot connect to database server java.lang.ClassNotFoundException
Upvotes: 0
Views: 17137
Reputation: 2667
To use the MYSQL Driver (Connector/J) you will need to download it from MySQL Connectors and put it in your classpath.
Upvotes: 2
Reputation: 2293
Download the jdbc-mysql driver here.
Include it in your classpath.
Upvotes: 1
Reputation: 32004
It seems that you should put your MySQL driver jar into your classpath.
Upvotes: 3