我已经安装了 MySQL 连接器 J、WAMP [MySQL 附带的] 和 Java JDK 1.7,但它总是通过异常com.mysql.jdbc.Driver
编码
import java.sql.*;
public class sou
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/cms";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
conn.close();
}
catch (Exception e)
{
System.err.println (e.getMessage());
}
}
}
我将其编译为
C:\Users\Sou\Desktop>javac -cp "D:\Program Files\MySQL\Connector J 5.1.20.0\mysql-connector-java-5.1.20-bin.jar" sou.java