package com.test.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * JDBCUtilSingle:JDBC helper class */ public final class JDBCUtilSingle { static String driver = "com.mysql.jdbc.Driver"; static String url = "jdbc:mysql://localhost:3306/website?useUnicode=true&charaterEncoding=utf-8"; static String username = "root"; static String password = "root"; static Connection conn = null; private static JDBCUtilSingle instance = null; private JDBCUtilSingle() { } /** * get JDBCUtilSingle instance * @return */ public static JDBCUtilSingle getInstance(){ if(instance == null){ synchronized(JDBCUtilSingle.class){ if(instance == null){ instance = new JDBCUtilSingle(); } } } return instance; } /** * static code block register database driven to ensure registration only one */ static{ try { Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); } } /** * get database Connection * @return Connection */ public Connection getConnection(){ try { conn = DriverManager.getConnection(url,username,password); } catch (SQLException e) { e.printStackTrace(); } return conn; } /** * close connection resource * @param rs * @param st * @param conn */ public void closeConnection(ResultSet rs, Statement st, Connection conn){ try { if(rs != null){ rs.close(); } } catch (SQLException e) { e.printStackTrace(); } finally{ try{ if(st != null){ st.close(); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(conn != null){ conn.close(); } }catch(Exception e){ e.printStackTrace(); } } } } }
最近下载更多
asddwh LV12
2023年12月29日
去码头整点薯条 LV3
2023年11月15日
ds9009 LV7
2023年8月7日
CH小老虎 LV1
2023年7月4日
sfy_1802661689 LV2
2023年7月3日
qwqwqw12345 LV3
2023年6月20日
ericxu1116 LV24
2023年6月14日
泓鼎168 LV19
2023年6月13日
微信网友_6470947892727808 LV1
2023年5月11日
kxjh星辰 LV6
2022年12月28日