org.gjt.mm.mysql.Driver是com.mysql.jdbc.Driver的前身,如果你的项目中用到的是org.gjt.mm.mysql.Driver驱动,只是为了兼容性。和用com.mysql.jdbc.Driver没区别。
但是现在的项目建议使用com.mysql.jdbc.Driver。下面是测试代码:
package com.evan.jdbc.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class JDBCdRIVERtEST { public static void main(String[] args) throws Exception { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String url = "jdbc:mysql://localhost:3306/evan"; String username = "root"; String password = "root"; String sql = "select * from user"; // String className = "org.gjt.mm.mysql.Driver"; String className = "com.mysql.jdbc.Driver"; Class.forName(className); conn = DriverManager.getConnection(url, username, password); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { System.out.println("user表里面有值" + rs.getString("name")); } } }