forked from pt4ebqrwy/Epidemic
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
875 B
30 lines
875 B
package com.liu.covid.util;
|
|
import java.sql.*;
|
|
public class JDBCUtils {
|
|
static final String url="jdbc:mysql://localhost:3306/covid?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";
|
|
static final String user="root";
|
|
static final String password="123456";
|
|
private static Connection con;
|
|
|
|
/**
|
|
* 连接数据库
|
|
* @return
|
|
*/
|
|
public static Connection getConnection(){
|
|
//添加驱动
|
|
try {
|
|
Class.forName("coym.msql.cj.jdbc.Driver");// 8.0以后版本加载驱动
|
|
}catch (ClassNotFoundException e){
|
|
e.printStackTrace();
|
|
}
|
|
//进行连接
|
|
try {
|
|
con= DriverManager.getConnection(url, user, password);
|
|
con.setAutoCommit(true);
|
|
}catch (SQLException e){
|
|
e.printStackTrace();
|
|
}
|
|
return con;
|
|
}
|
|
}
|