org.gjt.mm.mysql.Driver
org.gjt.mm.mysql.Driver是com.mysql.jdbc.Driver的前身,如果你的项目中用到的是org.gjt.mm.mysql.Driver驱动,只是为了兼容性。和用com.mysql.jdbc.Driver没区别。但是现在的项目建议使用com.mysql.jdbc.Driver。下面是测试代码:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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")); } } } |
分享到: