import java.sql.*;
public class ConnectMySql {
public static void main(String[] args) {
String sDBDriver="org.gjt.mm.mysql.Driver";
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.print("Connect to Database error: " + e.getMessage());
// e.printStackTrace();
System.out.println("----------------------");
}
try {
Statement stmt;
String url ="jdbc:mysql://localhost:3306/mysql";
Connection con =DriverManager.getConnection(url,"root", "hacker");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
stmt = con.createStatement();
stmt.executeUpdate("CREATE DATABASE JunkDB");
stmt.executeUpdate(
"GRANT SELECT,INSERT,UPDATE,DELETE," +
"CREATE,DROP " +
"ON JunkDB.* TO 'root'@'localhost' " +
"IDENTIFIED BY 'hacker';");
con.close();
}catch( Exception e ) {
e.printStackTrace();
System.out.println(e.toString());
}//end catch
}//end main
}
----------------------------------
下面是错误提示:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at ConnectMySql.main(ConnectMySql.java:19)
Connect to Database error: org.gjt.mm.mysql.Driver----------------------
java.sql.SQLException: No suitable driver