四月九日

今日所写代码:

package test;
import java.sql.*;
public class Test {

public static String db_url = "jdbc:mysql://localhost:3306/ceshi?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT";
public static String db_user = "root";
public static String db_password = "NN06280055";

public static Connection getConn() {
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(db_url, db_user, db_password);
System.out.println("连接成功");
} catch (Exception e) {
System.out.println("连接失败");
e.printStackTrace();
}
return conn;
}

public static void close(Statement state, Connection conn) {
if(state!=null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public static void close(ResultSet rs, Statement state, Connection conn) {
if(rs!=null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(state!=null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public static void main(String[] args)
{
return;
}
}

 

posted @ 2023-04-09 22:21  布吉岛???  阅读(13)  评论(0编辑  收藏  举报