title: Where is prepared statement precompiled, in jvm or in db?
body: <p>When reading across different posts a question came across the mind  Where is prepared statement precompiled, in jvm or in db? And when does the process actually happen in a java class. Example Below :=</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  
  public class PreparedStmtDemo {
  
  public static void main(String args[]) throws SQLException,Exception {
  
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","scott","tiger");
      PreparedStatement preStatement = conn.prepareStatement("select RollNo from student where Stream =?");
      preStatement.setString(1, "Commerce");
  
      ResultSet result = preStatement.executeQuery();
  
      while(result.next()){
          System.out.println("Roll No: " + result.getString("RollNo"));
      }       
  }
  </code></pre>
  
  <p>} </p>