zoukankan      html  css  js  c++  java
  • 简单的JdbcUtil 类

    
    import java.sql.*;
    
    /** JDBC工具类 */
    public class JdbcUtil {
      /**
       * 获取数据库连接对象并返回
       *
       * @return Connection对象
       * @throws Exception
       */
      public static Connection getConn() throws Exception {
        // 1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        // 2.获取连接
        Connection conn =
            DriverManager.getConnection(
                "jdbc:mysql://localhost:1054/jt_db?characterEncoding=utf8", "root", "123456");
        return conn;
      }
    
      /**
       * 释放JDBC程序中的资源
       *
       * @param conn 连接对象
       * @param stat 传输器对象
       * @param rs 结果集对象
       */
      public static void close(Connection conn, Statement stat, ResultSet rs) {
        if (rs != null) {
          try {
            rs.close();
          } catch (SQLException e) {
            e.printStackTrace();
          } finally {
            rs = null;
          }
        }
        if (stat != null) {
          try {
            stat.close();
          } catch (SQLException e) {
            e.printStackTrace();
          } finally {
            stat = null;
          }
        }
        if (conn != null) {
          try {
            conn.close();
          } catch (SQLException e) {
            e.printStackTrace();
          } finally {
            conn = null;
          }
        }
      }
    }
    

      

     
  • 相关阅读:
    6 完全平方数相关
    5 三位数,每个位置不同
    Neo4j Admin Import 导入多个node和relationship
    Rust所有权
    Rust 多态
    Rust 泛型
    Rust trait
    Rust模块化
    Spring Cloud(Dalston.SR1)
    git 速度慢问题解决
  • 原文地址:https://www.cnblogs.com/lxsfve/p/13232402.html
Copyright © 2011-2022 走看看