public class ParseCall
{
  public static void NoBinding(Connection conn, int count) 
  throws Exception{
    PreparedStatement stmt;
    ResultSet rs;

    for (int i = 1; i <= count; i++) {

       stmt= conn.prepareStatement(
         "SELECT /* no_binding */ " + i + "," + i + ",'test', a.* " +
         "FROM emp a WHERE a.ename LIKE 'W%'");
       rs=stmt.executeQuery();

       rs.close();
       stmt.close();
     }
  }

  public static void NoCaching(Connection conn, int count) 
  throws Exception{
    PreparedStatement stmt;
    ResultSet rs;

    for (int i = 1; i <= count; i++) {

       stmt= conn.prepareStatement(
         "SELECT /* no_caching */ ?,?,?,a.* " +
         "FROM emp a WHERE a.ename LIKE 'W%'");
       stmt.setInt(1,i);
       stmt.setInt(2,i);
       stmt.setString(3,"test");
       rs=stmt.executeQuery();

       rs.close();
       stmt.close();
     }
  }

  public static void CursorHolding(Connection conn, int count) 
  throws Exception{

    // PreparedStatement  ٱ 
    PreparedStatement stmt = conn.prepareStatement(
      "SELECT /* cursor_holding */ ?,?,?,a.* " +
      "FROM emp a WHERE a.ename LIKE 'W%'");
    ResultSet rs;

    for (int i = 1; i <= count; i++) {

       stmt.setInt(1,i);
       stmt.setInt(2,i);
       stmt.setString(3,"test");
       rs=stmt.executeQuery();
       rs.close();

     }

     //     Ŀ ݴ´. 
     stmt.close();
  }

  public static void CursorCaching(Connection conn, int count) 
  throws Exception{

    // ĳ  1 
    ((OracleConnection)conn).setStatementCacheSize(1);

    //  ĳ  Ȱȭ
    ((OracleConnection)conn).setImplicitCachingEnabled(true);

    for (int i = 1; i <= count; i++) {

       // PreparedStatement  ʿ 
       PreparedStatement stmt = conn.prepareStatement(
         "SELECT /* implicit_caching */ ?,?,?,a.* " +
         "FROM emp a WHERE a.ename LIKE 'W%'");
       stmt.setInt(1,i);
       stmt.setInt(2,i);
       stmt.setString(3,"test");
       ResultSet rs=stmt.executeQuery();

       rs.close();

       // Ŀ  δ   ä ĳÿ  
       stmt.close();
     }
  }

  public static void main(String[] args) throws Exception{
    String DB_CON     = "jdbc:oracle:thin:@localhost:1521:ora10g";
    String DB_USER    = "scott";
    String DB_PASS    = "tiger";

    DriverManager.registerDriver(new OracleDriver());
    Connection conn = DriverManager.getConnection(DB_CON,DB_USER,DB_PASS);
    conn.setAutoCommit(false);
    
    long btm = System.currentTimeMillis();

    // Bind   ʾ 
    NoBindingCase(conn, 5000);

    System.out.println("runBatch time : " + (System.currentTimeMillis() - btm));
    System.out.println("Enter To Continue...");
    java.io.BufferedReader in = new BufferedReader(new java.io.InputStreamReader(System.in));
    in.readLine();

    btm = System.currentTimeMillis();
		
		// Bind   Caching ɼ   
    NoCachingCase(conn, 5000);

    System.out.println("runBatch time : " + (System.currentTimeMillis() - btm));

    System.out.println("Enter To Continue...");
    in.readLine();

    btm = System.currentTimeMillis();

		// Bind  ϸ鼭 Caching ɼǵ Բ  
    CachingCase(conn, 5000);

    System.out.println("runBatch time : " + (System.currentTimeMillis() - btm));

    System.out.println("Enter To Continue...");
    in.readLine();

    btm = System.currentTimeMillis();

		// Cursor  ʰ ݺ  
    CursorHoldingCase(conn, 5000);

    System.out.println("runBatch time : " + (System.currentTimeMillis() - btm));

    conn.commit();
    conn.close();

  }

}

