import java.sql.*;

public class DBTest{
 public static void main(String args[]) throws Exception{
  new DBTest();
 }
 public DBTest(){
  Connection conn=null;
  Statement stmt=null;
  ResultSet rs=null;

  String sql="select * from en_contents";
  String url = "jdbc:oracle:thin:@192.168.1.50:1521:ORCL";
  String id = "myid";
  String pass = "mypass";

  try {
   //클래스를 메모리에 로딩 시키는 것
   Class.forName("oracle.jdbc.driver.OracleDriver"); 
  } catch (Exception e) {
   e.printStackTrace();
  }
  try {
   conn= DriverManager.getConnection(url,id,pass);
   stmt = conn.createStatement();
   rs=stmt.executeQuery(sql);
   while (rs.next()) {
    System.out.println(rs.getString(1));
   }

   if(rs!=null)rs.close();
   if(stmt!=null)stmt.close();
   if(conn!=null)conn.close();
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
}

+ Recent posts