protected static Connection getConnection() throws SQLException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/DB", "root", "root");
return conn;
}
连接mysql数据失败:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
原因:未引入数据库连接包mysql-connector-java-3.1.12-bin.jar
解决步骤:右键工程->properties->Java Build Path->Libraries->选择Add External Jars