Recent Posts

Monday, 12 November 2018

Working With Type-4 Driver

     Type-4 driver also known as Pure Java Driver OR Thin Driver. 

     Type-2 and Type-4 Drivers of Oracle having same Jar File, same Driver Class Name, but different JDBC URL's.
Driver Class Name : oracle.jdbc.driver.OracleDriver oracle.jdbc.OracleDriver
JDBC URL : jdbc:oracle:thin:@localhost:1521:XE

import java.sql.*;
/**
 * 
 * @author ashok.mariyala
 *
 */
public class Type4DbConnectDemo { 
   public static void main(String[] args) throws Exception { 
      Class.forName("oracle.jdbc.driver.OracleDriver"); 
      Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger"); 
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("select * from emp");
      while(rs.next()) {
         System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getString(4));
      }
      con.close();
   }
}

Next Tutorial : Working With Type-5 Driver

Previous Tutorial : Working with Type-3 Driver

No comments:

Post a Comment