1. Make Java Project
2. Download JDBC Driver
3. Add JDBC Driver
package oracle; import java.sql.*; public class test { public static void main(String[] args) { // TODO Auto-generated method stub Connection conn = null; ResultSet rs = null; Statement stmt = null; String url = null; String id = "jeon"; String pw = "jeon"; try{ url ="jdbc:oracle:thin:@localhost: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 * from TEST"); while(rs.next()){ String name = rs.getString(1); String pwd = rs.getString(2); System.out.println(name +", "+pwd); } stmt.close(); conn.close(); } catch (Exception e){ e.printStackTrace(); } } }
댓글 없음:
댓글 쓰기