zoukankan      html  css  js  c++  java
  • JDBC的简单封装

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    /**
     * 数据库连接工具
     * @author 2017
     *
     */
    public class DbTool {
        /**
         * 数据库的类
         */
        private static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
        /**
         * 主机地址和接口
         */
        private static final String URL = "jdbc:oracle:thin:@localhost:1521:XE";
        /**
         * 账户
         */
        private static final String USER = "";
        /**
         * 密码
         */
        private static final String PASSWORD = "";
        /**
         * 数据库的链接通道方法-Connection_conn
         * 
         */
        public static Connection getConnection(){
            try {
                //加载oracle数据驱动类
                Class.forName(ORACLE_DRIVER);
                //返回数据库通道对象
                return DriverManager.getConnection(URL, USER, PASSWORD);
            } catch (Exception e) {
                // TODO: handle exception
            }
            return null;
            
        }
        
        /**
         * 数据库的释放资源方法
         * Connection_conn
         * PreparedStatement_ps
         * ResultSet_rs
         */
        public static void close(Connection conn,PreparedStatement ps,ResultSet rs){
            try {
                if (rs!=null) {
                    rs.close();
                }
                if (ps!=null) {
                    ps.close();
                }
                if (conn!=null) {
                    conn.close();
                }
            } catch (Exception e) {
                //打印错误
                e.printStackTrace();
            }
        }
        /**
         * 数据库的释放资源方法
         *  Connection_conn
         *  PreparedStatement_ps
         */
        public static void close(Connection conn,PreparedStatement ps){
            try {
                
                if (ps!=null) {
                    ps.close();
                }
                if (conn!=null) {
                    conn.close();
                }
            } catch (Exception e) {
                //打印错误
                e.printStackTrace();
            }
        }
        
    }
  • 相关阅读:
    hdu 2842 Chinese Rings
    Codeforces Round #118 (Div. 1) A 矩阵快速幂
    hdu2604 Queuing
    支付宝 生活号 获取 userId 和 生活号支付
    maven 项目使用本地jar
    nexus 私有 maven 仓库的搭建
    linux jdk 安装
    gitlab 可以上传代码,但是 不能 上传 tag 问题
    maven 内置变量
    mysql 不允许分组的问题 this is incompatible with sql_mode=only_full_group_by
  • 原文地址:https://www.cnblogs.com/wqsbk/p/7346252.html
Copyright © 2011-2022 走看看