@Test
public void test2() throws Exception{
Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
Object o = aClass.newInstance();
Driver driver = (Driver) o;
String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8";
Properties info=new Properties();
info.setProperty("user","xxxxx");
info.setProperty("password","xxxxx");
Connection connection=driver.connect(url,info);
System.out.println(connection);
}
@Test
public void test3() throws Exception {
Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
Object o = aClass.newInstance();
Driver driver = (Driver) o;
DriverManager.registerDriver(driver);
String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8";
String user="xxxxx";
String password="xxxxx";
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(connection);
}
@Test
public void test4() throws Exception {
String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8";
String user="xxxxx";
String password="xxxxx";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(connection);
}
@Test
public void test5() throws Exception {
InputStream resource = ConnectionTest.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties pt=new Properties();
pt.load(resource);
String user = pt.getProperty("user");
String password = pt.getProperty("password");
String url = pt.getProperty("url");
String driverClass = pt.getProperty("driverClass");
Class.forName(driverClass);
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(connection);
}
#properties中的配置信息
url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8
user=xxxx
password=xxxx
driverClass=com.mysql.cj.jdbc.Driver