/**
* JDBC之MySQL工具类
*
* @author: Rodge
* @time: 2018年10月4日 下午4:03:42
* @version: V1.0.0
*/
public class JDBCUtilForMySQL {
private static final String URL = "jdbc:mysql://localhost:3306/test";
private static final String USER = "root";
private static final String PASSWORD = "1234";
private static Connection conn = null;
static {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取数据库连接
* @return
*/
public static Connection getConnection () {
return conn;
}
public static void main(String[] args) {
System.out.println(JDBCUtilForMySQL.getConnection());
}
}