I had problems with procedure cache when executing a large batch. I want to execute the batch every 1000 records have been added. What follows is the original post I intended to write.

I'm trying to run an executeBatch command inside a while loop that gets parameters from a resultSet. When a certain amount of commands have been added (1000) I want to execute the batch, and then continue adding commands and executing in batches of 1000 commands. The problem is the executeBatch doesn´t run at all, the app just stops dead it seems to get locked executing the batch. If I add all the commands from the resultSet and run executeBatch at the end, outside of the while loop, it works, but I run the risk of sending too many commands to the Database (Sybase 12.5). Any advice on how to achieve this? Thanks a lot

Code snippet
Notice I'm not running the batch on the same resultSet that I'm getting results from, and the inserts don't affect the tables involved in the executeQuery.

CallableStatement csSentencia;
csSentencia = scConexion.prepareCall("{call procedure}");
ResultSet rs = csSentencia.executeQuery();

Statement st;

int i = 0;

while(rs.next()) {


/* This insert uses data gathered from the resultSet */
String strsql="Insert into ....................... ";


/* Execute batch every 1000 records */
if (i%1000 == 0){
/* If I leave just this part, it works fine
I have to leave it anyway to execute the rest of the commands if its not
multiple of 1000 */