萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> org.gjt.mm.mysql.Driver

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"));         }     } }
copyright © 萬盛學電腦網 all rights reserved