package com.syc.java;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost/logoshop", "root", "root");
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void closeConnection(Connection conn){
if(conn!=null){
try {
conn.close();
conn=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static Statement getStatement(Connection conn){
Statement state=null;
try {
state=conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return state;
}
public static void closeStatement(Statement state){
if(state!=null){
try {
state.close();
state=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static PreparedStatement getPreparedStatement(Connection conn,String sql){
PreparedStatement pstate=null;
try {
pstate=conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pstate;
}
public static PreparedStatement getPreparedStatement(Connection conn,String sql,boolean is){
PreparedStatement pstate=null;
try {
pstate=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
} catch (SQLException e) {
e.printStackTrace();
}
return pstate;
}
public static ResultSet executeQuery(Statement state,String sql){
ResultSet reSet=null;
try {
reSet=state.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return reSet;
}
public static void closeResultSet(ResultSet reSet){
if(reSet!=null){
try {
reSet.close();
reSet=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
最近下载更多
komorebi123987 LV5
2023年12月9日
qiuaizhang LV3
2023年4月10日
copy1000 LV1
2022年9月30日
00000007 LV1
2022年7月15日
284650 LV1
2022年6月12日
illkih LV2
2022年3月17日
3361758107 LV1
2021年12月19日
201901150233 LV1
2021年12月12日
A Lazy dog LV1
2021年12月11日
mwk545924364 LV4
2021年12月9日
最近浏览更多
微信网友_7562058687860736
6月20日
暂无贡献等级
wwy000 LV2
4月29日
asashx
2024年12月26日
暂无贡献等级
Mhgfhjyrf LV3
2024年12月9日
我做梦 LV2
2024年12月3日
吴明艳
2024年11月25日
暂无贡献等级
微信网友_7060373407682560 LV1
2024年7月1日
15719908287 LV10
2024年6月19日
kuyedie LV1
2024年6月17日
xcccffff LV1
2024年6月11日

