Advertisement
uopspop

Untitled

Aug 12th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class ResultSet1 {
  4.  
  5.     public static void main(String[] args) throws Exception{
  6.         // TODO Auto-generated method stub
  7.         String JDBCDrivers = "oracle.jdbc.driver.OracleDriver";
  8.         String useThisDriver_url = "jdbc:oracle:thin:@localhost:1521:xe";
  9.        
  10.         Class.forName(JDBCDrivers);
  11.         Connection con = DriverManager.getConnection(useThisDriver_url,"user08","1111");
  12.         Statement stmt = con.createStatement();
  13.         ResultSet rs = stmt.executeQuery("SELECT * from EMP2");
  14.         while(rs.next()){
  15.             Integer col1 = rs.getInt(1);
  16.             String col2 = rs.getString("ename");
  17.             System.out.print("EMPNO: " + col1.toString() );
  18.             System.out.print("\tENAME:  " + col2.toString());
  19.             System.out.println();
  20.         }
  21.         rs.close(); stmt.close(); con.close();
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement