package com.qm.shishang.util;

import static com.qm.shishang.util.LoadDBconfig.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 数据库操类
 * @author quanmin
 *
 */
public class DBUtil {

	/**
	 * 连接数据库
	 * @return
	 */
	public static Connection getConn(){
		Connection conn=null;
		try {
			//加载驱动
			Class.forName(getDBValue("driverclass"));
			String url=(getDBValue("url"));
			String user=(getDBValue("username"));
			String password=(getDBValue("password"));
			conn=DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	/**
	 * 关闭连接
	 * @param rs
	 * @param stat
	 * @param conn
	 */
	public static void closeConn(ResultSet rs,Statement stat,Connection conn){
		try {
			// 关闭 ctrl+shift+F format
			if (rs != null) {
				rs.close();
			}
			if (stat != null) {
				stat.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void closeConn(Statement stat,Connection conn){
		try {
			
			if (stat != null) {
				stat.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
jiemomo  LV12 2023年10月18日
慵懒的小橘猫  LV11 2022年12月24日
000666  LV10 2022年12月24日
liangge2115  LV27 2022年11月13日
chenhan413  LV10 2022年5月5日
沆辙1111  LV6 2022年4月17日
微信网友_5862759611551744  LV1 2022年3月9日
采暖11  LV11 2021年12月6日
wanglinddad  LV54 2021年11月28日
drunkery-cat  LV4 2021年10月12日
最近浏览更多
Jim_joker  LV1 4月25日
tartaglia  LV2 4月16日
xuweiwowzy  LV5 1月14日
asddwh  LV12 2023年12月25日
jiemomo  LV12 2023年10月18日
zdfxcv  LV1 2023年10月14日
joker1branch  LV5 2023年6月19日
jjxxzz  LV1 2023年5月29日
yzshabzbbdvw  LV4 2023年4月13日
gala209  LV3 2023年2月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友