package day1118_jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import org.junit.Test;
public class GetConnection {
private static Connection connection = null;
private static String className = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false";
private static String user = "root";
private static String password = "wangjian";
@Test
public void testConnection() { //测试下面数据库的链接
getConnection();
}
public static Connection getConnection() {
try {
Class.forName(className);
connection = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(connection);
return connection;
}
}