package com; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Properties; public class DBUtil { private static String url; private static String driver; private static String user; private static String password; static { try { ClassLoader classLoader = DBUtil.class.getClassLoader(); InputStream is = classLoader .getResourceAsStream("config/props/db.properties"); Properties props = new Properties(); props.load(is); url = props.getProperty("url"); driver = props.getProperty("driver"); user = props.getProperty("user"); password = props.getProperty("password"); // regist drawing Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new RuntimeException(""); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(""); } } // get connect public static Connection getConnection() throws Exception { return DriverManager.getConnection(url, user, password); } // close connect public static void close(ResultSet rs, Statement smt, Connection conn) throws Exception { if (rs != null) { rs.close(); } if (smt != null) { smt.close(); } if (conn != null) { conn.close(); } } public static void close(Statement smt, Connection conn) throws Exception { close(null, smt, conn); } public static void main(String[] args) throws Exception { System.out.println(getConnection()); } // close connection with resultset }

chenkaizhen LV1
2021年11月26日
zhj7181 LV1
2021年7月4日
totcom LV1
2021年3月3日
邈话12123 LV9
2020年10月29日
duke最拽 LV3
2020年10月22日
能不能不存在 LV13
2020年5月11日
kangran LV1
2020年4月17日
wanminhang LV12
2020年3月15日
3030617253 LV2
2019年11月30日
时空12580 LV13
2019年1月6日