ideal
mysql驱动5.1.46
jdk8
public static void main(String[] args) {
try {
Class clzz = Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Connection conn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","root");
} catch (SQLException e) {
e.printStackTrace();
}
}
package com.mysql.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Driver extends NonRegisteringDriver implements java.sql.Driver {
public Driver() throws SQLException {
}
static {
try {
DriverManager.registerDriver(new Driver());
} catch (SQLException var1) {
throw new RuntimeException("Can't register driver!");
}
}
}
public static void registerDriver(Driver driver) throws SQLException {
registerDriver(driver, (DriverAction)null);
}
public static void registerDriver(Driver driver, DriverAction da) throws SQLException {
if (driver != null) {
registeredDrivers.addIfAbsent(new DriverInfo(driver, da));
println("registerDriver: " + driver);
} else {
throw new NullPointerException();
}
}
@CallerSensitive
public static Connection getConnection(String url, String user, String password) throws SQLException {
Properties info = new Properties();
if (user != null) {
info.put("user", user);
}
if (password != null) {
info.put("password", password);
}
return getConnection(url, info, Reflection.getCallerClass());
}
private static Connection getConnection(String url, Properties info, Class<?> caller) throws SQLException {
ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
if (callerCL == null || callerCL == ClassLoader.getPlatformClassLoader()) {
callerCL = Thread.currentThread().getContextClassLoader();
}
if (url == null) {
throw new SQLException("The url cannot be null", "08001");
} else {
println("DriverManager.getConnection(\"" + url + "\")");
ensureDriversInitialized();
SQLException reason = null;
Iterator var5 = registeredDrivers.iterator();
while(true) {
while(var5.hasNext()) {
DriverInfo aDriver = (DriverInfo)var5.next();
if (isDriverAllowed(aDriver.driver, callerCL)) {
try {
println(" trying " + aDriver.driver.getClass().getName());
Connection con = aDriver.driver.connect(url, info);
if (con != null) {
println("getConnection returning " + aDriver.driver.getClass().getName());
return con;
}
} catch (SQLException var8) {
if (reason == null) {
reason = var8;
}
}
} else {
println(" skipping: " + aDriver.getClass().getName());
}
}
if (reason != null) {
println("getConnection failed: " + reason);
throw reason;
}
println("getConnection: no suitable driver found for " + url);
throw new SQLException("No suitable driver found for " + url, "08001");
}
}
}