mySqlClass.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306:test"; Connection conn = DriverManager.getConnection(url, "root", "root"); }jdbc具体代码:public class DBUtil { //String sDBDriver = "oracle.jdbc.driver.OracleDriver"; String sDBDriver="com.mysql.jdbc.Driver"; String url="jdbc:mysql://localhost:goods"; //String url = "jdbc:oracle:thin:@10.74.10.225:1521:myoracle"; String sHint = ""; ResultSet rs = null; Connection conn = null; Statement stmt = null; String user = "test"; String pwd = "123456"; // 初始化 public boolean initialize(String dbDrive, String dbConn, String user, String pwd) { sDBDriver = dbDrive; url = dbConn; user = user; pwd = pwd; return initialize(); } // 初始化 public boolean initialize() { try { Class.forName(sDBDriver); sHint = "Initialization sucessfully"; return true; } catch (ClassNotFoundException e) { sHint = "Initialization Exception:" + e.getMessage(); return false; } } // 执行查询语句 public ResultSet executeQuery(String sql) { rs = null; try { conn = DriverManager.getConnection(url, user, pwd); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch (SQLException ex) { sHint = "Query Exception:" + ex.getMessage(); } return rs; } // 执行更新语句 public boolean executeUpdate(String sql) { try { conn = DriverManager.getConnection(url, user, pwd); stmt = conn.createStatement(); stmt.executeUpdate(sql); return true; } catch (SQLException ex) { sHint = "Update Exception :" + ex.getMessage(); return false; } } // 关闭连接、结果集、statemernt,释放资源 public boolean close() { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (conn != null) conn.close(); return true; } catch (SQLException ex) { sHint = "Close Exception:" + ex.getMessage(); return false; } } public String getSHint() { return sHint; } public void setSDBDriver(String dbDriver) { sDBDriver = dbDriver; } public String getSDBDriver() { return sDBDriver; } public String getUrl() { return url; } public void setUrl(String s) { url = s; } public ResultSet getResultSet() { return rs; } }