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();
}
}
}

原文地址:https://www.cnblogs.com/xiaopangyu/p/9330154.html