import java.sql.*;
public class GetSysdate {
public static void main(String[] args) throws Exception {
// 오라클 DB 접속 설정
String url = "jdbc:oracle:thin:@DESCRIPTION-(FAIL_OVER=on)(LOAD_BALANCE=on)(ADDRESS=(PROTOCAL=TCP)(HOST=/*host-ip*/(PORT=/*port*/))(ADDRESS=PROTOCAL=TCP(HOST=/*host-ip*/)(PORT=/*port*/))(CONNECT_DATA=(SERVICE_NAME=/*SID*/)))";
String id = "/*ID*/";
String pwd = "/*PW*/";
Connection con = null; // Connection 객체 변수 선언
ResultSet rs = null; // ResultSet 객체 변수 선언
Statement stmt = null; // Statement 객체 변수 선언
String date = "";
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // Class.forName("[드라이버명]");
con = DriverManager.getConnection(url, id, pwd);
stmt = con.createStatement();
String query = "SELECT SYSDATE FROM DUAL"; // 쿼리문
rs = stmt.executeQuery(query); // 쿼리실행
System.out.println("query : " + query);
if (rs.next()) {
date = rs.getString("SYSDATE"); // SYSDATE를 String값으로 받아오기
}
System.out.println("date : " + date);
} catch (Exception e) {
System.out.println("Test / 오류 : " + e);
} finally {
if (rs != null)
try {
rs.close();
} catch (SQLException ex) {
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException ex) {
}
if (con != null)
try {
con.close();
} catch (SQLException ex) {
}
}
}
}
}
반응형
'Programming > JAVA' 카테고리의 다른 글
Error: Could not find the required version of the Java(TM) 2 Runtime Environment in'(null)'. (0) | 2013.04.18 |
---|