package com.dxf.two_day;
import java.sql.*;
/**
* Created by Administrator on 2017/12/10 0010.
*mysql jdbc 连接类
*/
public class DBTool {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
static String url="jdbc:mysql://localhost:3306";
static String user="root";
static String password="root";
public static Connection getCon(){
try {
return DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void close(Connection con){
if (con!=null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(PreparedStatement pstmt){
if (pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(Statement stmt){
if (stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(ResultSet rs){
if (rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void rollback(Connection con){//事件回滚
try {
con.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
mysql jdbc 连接类
最新推荐文章于 2022-04-18 08:00:00 发布