数据库公共类代码

package com.shk.util;

import java.sql.Connection;

import java.sql.DriverManager;

public class GetConnection

{

private static Connection conn=null;

private static String address="jdbc:mysql://localhost:3306/data1?useSSL=true&serverTimezone-UTC";

private static String dataBaseName="root";

private static String dataBasePwd="521616";

public static Connection getConn() {

if(conn==null) {

try {

Class.forName("com.mysql.cj.jdbc.Driver");

conn=DriverManager.getConnection(address, dataBaseName, dataBasePwd);

} catch (Exception e) {

e.printStackTrace();

System.out.println("连接失败");

}

}

return conn;

}

}

你可能感兴趣的:(数据库公共类代码)