0
点赞
收藏
分享

微信扫一扫

连接orcale

东林梁 2022-01-12 阅读 43
package com.asiniafo.dpi_new.dpi.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 连接oracle
 */
public class DBUtilSjzx {
    private static String driver = "oracle.jdbc.driver.OracleDriver";
    private static String url = "jdbc:oracle:thin:@ip:端口:数据库名";
    private static String username = "";
    private static String password = "";

    public static Connection getConnection() {
        Connection con = null;
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url,username,password);
            return con;
        }catch (Exception e){
            e.printStackTrace();
        }
        return con;
    }

    /**
     * 关闭oracle数据库连接
     */
    public static void close(Connection con, PreparedStatement pstmt, ResultSet rs){
        //关闭rs
        try {
            if (rs != null && !(rs.isClosed())){
                rs.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //关闭PreparedStatement
        try {
            if (pstmt != null && !(pstmt.isClosed())){
                pstmt.close();
            }
        }catch (Exception e ){
            e.printStackTrace();
        }
        //关闭Connection
        try {
            if (con != null && !(con.isClosed())){
                con.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
举报

相关推荐

orcale数据结构

0 条评论