Java 在for循环中使用JPA StoredProcedureQuery执行过程的最佳方法
在for循环中执行过程的最佳方式是什么 这就是我所拥有的(这个“for”在未来会略有不同,但基本上是一样的): 我不能用这个游标在DB中创建SP,因为我们需要将这个执行迁移到JavaJava 在for循环中使用JPA StoredProcedureQuery执行过程的最佳方法,java,spring-boot,performance,jpa,Java,Spring Boot,Performance,Jpa,在for循环中执行过程的最佳方式是什么 这就是我所拥有的(这个“for”在未来会略有不同,但基本上是一样的): 我不能用这个游标在DB中创建SP,因为我们需要将这个执行迁移到Java 感谢您的帮助 我认为可以批量执行存储过程,但需要在普通jdbc中执行: Connection con = this.entityManager.unwrap(Session.class).connection(); CallableStatement stmt = con.prepareCall("{ c
感谢您的帮助 我认为可以批量执行存储过程,但需要在普通jdbc中执行:
Connection con = this.entityManager.unwrap(Session.class).connection();
CallableStatement stmt = con.prepareCall("{ call testProcedure(?,?,?) }");
for(int i=0; i<300; i++){
stmt.setString(1, "DF");
stmt.setInt(2, i);
stmt.setString(3, "F");
stmt.addBatch();
}
int [] updatesCount = stmt.executeBatch();
// Verify if all updatesCount is >= 0
Connection con=this.entityManager.unwrap(Session.class.Connection();
CallableStatement stmt=con.prepareCall(“{calltestprocedure(?,?)}”);
对于(int i=0;i=0
但为什么不在数据库中的过程中执行此操作呢?如果需要将消息放入队列(示例)进程执行后,您可以让存储过程用结果填充一个临时表,以便在java代码中执行此操作。谢谢!这样做可以提高执行性能。由于此执行迁移到java,我无法将此执行放在过程中(在程序中这样做是我的第一个想法,但这是一个我力所不及的决定)。
DECLARE
CURSOR cur IS select s_number from testTable where s_number in ( “some numbers (List)”);
BEGIN
FOR c IN cur LOOP
testProcedure('DF', c.s_number, 'F');
END LOOP;
commit;
END;
Connection con = this.entityManager.unwrap(Session.class).connection();
CallableStatement stmt = con.prepareCall("{ call testProcedure(?,?,?) }");
for(int i=0; i<300; i++){
stmt.setString(1, "DF");
stmt.setInt(2, i);
stmt.setString(3, "F");
stmt.addBatch();
}
int [] updatesCount = stmt.executeBatch();
// Verify if all updatesCount is >= 0