Oracle 应用程序服务器中可调用和已准备语句的行为

Oracle 应用程序服务器中可调用和已准备语句的行为,oracle,jdbc,database-connection,Oracle,Jdbc,Database Connection,CallableStatement和PreparedStatement是预编译的。它们是针对连接完成的吗?我的意思是,假设有大约100个连接对象驻留在应用服务器的连接池中。有一个类使用Callable和PreparedStatements。让我们假设用于此的方法是: public void invokePreparedAndCallableStatements(){ //Fetches connection from pool Connection con = getConne


CallableStatement和PreparedStatement是预编译的。它们是针对连接完成的吗?我的意思是,假设有大约100个连接对象驻留在应用服务器的连接池中。有一个类使用Callable和PreparedStatements。让我们假设用于此的方法是:

public  void invokePreparedAndCallableStatements(){  
  //Fetches connection from pool  
  Connection con = getConnectionFromPool();
  CallableStatement cs = con.prepareCall(.....);
  cs.register...(...);
  cs.execute();
  ...
  ...
  PreparedStatement st = con.prepareStatement(...);
  st.setXXX(..);
  st.executeUpdate();
  ...
 }
现在,当第一次调用该方法时,将从池中获取连接并处理请求。编译可调用和准备好的语句。当该方法被再次调用99次时,每次从池中获取不同的连接时,那么-每个连接的语句都会被遵守吗?

在这种情况下,使用语句的最佳方式是什么?我无法将它们(con.prepareCall()或con.prepareStatement())设置为静态,因为连接不是静态的。

代码实际上是编译并存储在数据库的共享池中的。使用相同代码的任意数量的连接都将受益于缓存。只要内存限制允许,编译后的代码就会被保留。

语句将被预编译。池将基于您指定的参数


注意:如果您使用的是JDBC3.0,那么还可以将PreparedStatements合并到一起。参考资料:

谢谢。同一个PL/SQL过程是否有办法为同一代码提供多个编译版本?