JDBC连接数据库封装

package com.jiuqi.jdbc;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class JDBCUtil {
public static Connection getConn(){
Connection conn = null;
try {
Class.forName(ORACLE_DRIVER);
conn = DriverManager.getConnection(URL_PREFIX + SERVER_ADDRESS + SEMICOLON + SERVER_PORT + SEMICOLON + SID 
, USER_NAME,PASSWORD);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}

public static void close(AutoCloseable... args){
try {
for(int i = 0; i < args.length ; i++){
AutoCloseable o = args[i];
if(o != null){
o.close();
o = null;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver"; 
private static final String URL_PREFIX = "jdbc:oracle:thin:@"; 
private static final String SERVER_ADDRESS = "10.1.30.104"; 
private static final String SERVER_PORT = "1521";
private static final String  SID = "jttjjc";
private static final String  USER_NAME = "user_aqyj_yw";
private static final String PASSWORD = "user_aqyj_yw";
private static final String SEMICOLON = ":";


}

你可能感兴趣的:(数据库,Java基础)