连接orcale

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();
        }
    }
}
上一篇:C#使用Ado.net读取Excel表的代码


下一篇:python连接数据库的操作