아래의 소스를 오라클 정보(
URL,ID,PW)만 수정하고 jdbc_sample.java 파일로 만든다.
import java.sql.*;
public class jdbc_ex01 {
public static void main(String[] args)
{
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String url = null;
String id = "hr";
String pw = "hr";
try{
url ="jdbc:oracle:thin:@10.0.0.2:1521:ORCL";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url,id,pw);
System.out.println("DB connection complete");
stmt = conn.createStatement();
rs = stmt.executeQuery("select userid,userpw from admin");
while(rs.next()){
String userid = rs.getString(1);
String userpw = rs.getString(2);
System.out.println(userid +", "+userpw);
}
stmt.close();
conn.close();
} catch (Exception e){
e.printStackTrace();
}
}
}