package util; import java.io.IOException; import java.io.InputStream; import java.sql.*; import java.util.Properties; public class JdbcUtil { private static final String URL = "url"; private static final String DBINFO_FIIE_NAME = "dbinfo.properties"; private static Properties infos = new Properties(); private static String url = null; static{ InputStream is = JdbcUtil.class .getClassLoader() .getResourceAsStream(DBINFO_FIIE_NAME); try { infos.load(is); } catch (Exception e) { e.printStackTrace(); throw new ExceptionInInitializerError("属性文件加载错误"); } finally { try { is.close(); } catch (Exception e) { } } url = infos.getProperty(URL); } public static Connection getConnection() { try { return DriverManager.getConnection(url, infos); } catch (SQLException e) { e.printStackTrace(); } return null; } public static void close(ResultSet rs, Statement stat, Connection con) { try { rs.close(); } catch (Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); } try { stat.close(); } catch (Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); } try { con.close(); } catch (Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); } } public static void main(String[] args){ System.out.println(JdbcUtil.getConnection()); } }
- 粉丝: 14
- 资源: 5
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言-leetcode题解之70-climbing-stairs.c
- C语言-leetcode题解之68-text-justification.c
- C语言-leetcode题解之66-plus-one.c
- C语言-leetcode题解之64-minimum-path-sum.c
- C语言-leetcode题解之63-unique-paths-ii.c
- C语言-leetcode题解之62-unique-paths.c
- C语言-leetcode题解之61-rotate-list.c
- C语言-leetcode题解之59-spiral-matrix-ii.c
- C语言-leetcode题解之58-length-of-last-word.c
- 计算机编程课程设计基础教程