Sunday, August 16, 2015

JDBC Steps

1) Load the driver class.
    Class.forName("oracle.jdbc.driver.OracleDriver");


2) Create the connection Object.
    Connection con = DriverManager.getConnection  
    ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");


3) Create the statement Object.
     Statement stmt = con.createStatement();


4) Execute query.
     ResultSet rs = stmt.executeQuery("select * from emp");
     
     while (rs.next)
     {
        System.out.println(rs.getString());
     }


5) Close the conneciton Object.
     con.close();

No comments:

Post a Comment

Home