관리 메뉴

moozi

oracle jdbc 기초 본문

TIS_2017/응용sw_1기

oracle jdbc 기초

moozi 2016. 12. 26. 11:11

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;


public class JDBCTest {


public static void main(String[] args) {

Connection conn = null;

       ResultSet rs = null;

       Statement stmt = null;

       String url = null;

       String id = "hr";

       String pw = "1234";

   

       try{

   

           url ="jdbc:oracle:thin:@localhost:1521:orcl";

           Class.forName("oracle.jdbc.driver.OracleDriver");

           conn = DriverManager.getConnection(url,id,pw);

           

           System.out.println("연결되었습니다.");

               

           stmt = conn.createStatement();

           rs = stmt.executeQuery("select * from employees");

   

           while(rs.next()){

               String employeeId = rs.getString(1);

               String firstName = rs.getString(2);

               String lastName = rs.getString(3);

               System.out.println(employeeId+", " + firstName +", "+lastName);

           }

  

           stmt.close();

           conn.close();

  


       } catch (Exception e){

           e.printStackTrace();

       }

}


}



'TIS_2017 > 응용sw_1기' 카테고리의 다른 글

jdbc연습문제01  (0) 2016.12.26
orcle jdbc 기초2  (0) 2016.12.26
oracle연습문제05  (0) 2016.12.23
오라클 DB생성  (0) 2016.12.23
oracle연습문제04  (0) 2016.12.22
Comments