日期:2014-05-16 浏览次数:20487 次
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=utf-8";
String user = "";
String psw = "";
Connection con = DriverManager.getConnection(url,user,psw); com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver(); //or: //new com.mysql.jdbc.Driver(); String url = "jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=utf-8"; String user = ""; String psw = ""; Connection con = DriverManager.getConnection(url,user,psw);
com.mysql.jdbc.Driver driver = null;
//or:
ClassLoader cl = new ClassLoader();
cl.loadClass("com.mysql.jdbc.Driver"); package com.mysql.jdbc
public class Driver extends NonRegisteringDriver implements java.sql.Driver {
// ~ Static fields/initializers
// --------------------------------------------- //
// Register ourselves with the DriverManager
//
static {
t ry {
java.sql.DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}
// ~ Constructors
// -----------------------
/**
* Construct a new driver and register it with DriverManager
*
* @throws SQLException
* if a database error occurs.
*/
public Driver() throws SQLException {
// Required for Class.forName().newInstance()
}
}