package com.git.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class UserUtil {
//定義一個方法,返回connection對象
public static Connection retrunConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
//2.建立连接
String url = "jdbc:mysql://localhost:3306/jsp?characterEncoding=utf-8";
String username = "root";
String password = "123456";
Connection con = DriverManager.getConnection(url, username, password);
return con;
}
public static void closeIO(Connection con,PreparedStatement ps,ResultSet rs) throws Exception{
if(rs != null) {
rs.close();
}
if(ps != null) {
ps.close();
}
if(con != null) {
con.close();
}
}
public static void closeConAndPs(Connection con,PreparedStatement ps) throws Exception{
if(ps != null) {
ps.close();
}
if(con != null) {
con.close();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class UserUtil {
//定義一個方法,返回connection對象
public static Connection retrunConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
//2.建立连接
String url = "jdbc:mysql://localhost:3306/jsp?characterEncoding=utf-8";
String username = "root";
String password = "123456";
Connection con = DriverManager.getConnection(url, username, password);
return con;
}
public static void closeIO(Connection con,PreparedStatement ps,ResultSet rs) throws Exception{
if(rs != null) {
rs.close();
}
if(ps != null) {
ps.close();
}
if(con != null) {
con.close();
}
}
public static void closeConAndPs(Connection con,PreparedStatement ps) throws Exception{
if(ps != null) {
ps.close();
}
if(con != null) {
con.close();
}
}
}