zoukankan      html  css  js  c++  java
  • JDBC -Utils

     1 public class JDBCUtils {
     2 
     3     public static Connection getConnection() throws Exception {
     4         InputStream is = ClassLoader.getPlatformClassLoader().getResourceAsStream("jdbc.properties");
     5         Properties properties = new Properties();
     6         properties.load(is);
     7 
     8         String user = properties.getProperty("user");
     9         String password = properties.getProperty("password");
    10         String url = properties.getProperty("url");
    11         String driverClass = properties.getProperty("driverClass");
    12         // Load the driver
    13         Class.forName(driverClass);
    14 
    15         Connection conn = DriverManager.getConnection(url, user, password);
    16 
    17         return conn;
    18     }
    19 
    20     public static void closeConnect(Connection conn, Statement statement) {
    21         try {
    22             if (conn != null)
    23                 conn.close();
    24         } catch (SQLException throwables) {
    25             throwables.printStackTrace();
    26         }
    27         try {
    28             if (statement != null)
    29                 statement.close();
    30         } catch (SQLException throwables) {
    31             throwables.printStackTrace();
    32         }
    33     }
    34 }
  • 相关阅读:
    货币系统
    纸牌
    活动
    KKT-黑白球
    POJ2676-Sudoku
    POJ1717-Dominoes
    POJ1088-滑雪
    POJ1862-Stripies
    POJ2531-Network Saboteur
    2019.12.13 数的划分
  • 原文地址:https://www.cnblogs.com/yhc-love-cl/p/15004302.html
Copyright © 2011-2022 走看看