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日
最近浏览更多
ljhgff  LV1 1月20日
暂无贡献等级
a2418735612  LV1 1月4日
123456huv 1月2日
暂无贡献等级
微信网友_6802396587266048 2023年12月31日
暂无贡献等级
zhangjilu  LV18 2023年12月31日
asddwh  LV12 2023年12月29日
zz030701  LV1 2023年12月27日
原一鸣 2023年12月25日
暂无贡献等级
微信网友_6786215447367680  LV4 2023年12月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友