zoukankan      html  css  js  c++  java
  • JDBCUtil

    package com.links.dao.impl;

    import java.sql.*;

    public class JDBCUtil {
    // 数据库驱动类�?
    private static final String Driver = "oracle.jdbc.driver.OracleDriver";
    // 数据库地�?
    private static final String url = "jdbc:oracle:thin:@192.168.99.201:1521:TEST";
    // 用户
    private static final String user = "test02";
    // 密码
    private static final String pwd = "test02";

    /**
    * 创建数据库链接conn对象
    * @return
    */
    public static Connection getConnection() {
    Connection conn = null;
    try {
    // 虚拟机装载驱动类
    Class.forName(Driver);
    // 连接数据�?
    conn = DriverManager.getConnection(url, user, pwd);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return conn;
    }

    /**
    *
    * @param conn 数据库的链接对象
    * @param stmt 无参数操作数据库的对�?
    * @param psmt 有参数操作数据库的对�?
    * @param rs 返回结果�?
    */
    public static void close(Connection conn, Statement stmt, PreparedStatement psmt, ResultSet rs) {
    try {
    if (rs != null) {
    rs.close();
    }
    if (psmt != null) {
    psmt.close();
    }
    if (stmt != null) {
    stmt.close();
    }
    if (conn != null) {
    conn.close();
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

  • 相关阅读:
    openssh升级
    Mysql基础学习_Windows版(一)
    centos7 取消Ctrl+Alt+Del重启功能
    linux shell数值比较和字符串比较
    linux 使用中括号进行条件判断
    VXLAN简介(摘抄)
    centos配置NTP服务器
    Centos配置网卡子接口
    组播___IGMP
    组播
  • 原文地址:https://www.cnblogs.com/xiaopangyu/p/9330154.html
Copyright © 2011-2022 走看看