- 프로젝트에 lib (라이브러리 폴더 생성) 우클릭 > Build Path > Configure build path > Libraries
Add External JARS 선택
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class CommonJDBCUtil {
private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String URL = "jdbc:oracle:thin:@'IP주소':1521:xe";
private static final String USER = "five";
private static final String PASSWORD = "five";
//static 초기화 구문
static {
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//DB연결 Connection 객체 생성
public static Connection getConnection() {
try {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static void close(Connection conn, PreparedStatement pstmt, ResultSet rs) {
try {
if(rs != null) rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(pstmt != null) pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(Connection conn, PreparedStatement pstmt) {
try {
if(pstmt != null) pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}