problems with addBatch()

From: Parvinder Singh Arora <minkuarora_at_yahoo.com>
Date: 23 Jan 2002 02:37:19 -0800
Message-ID: <e7c950a4.0201230237.59f70b95_at_posting.google.com>


I have some problems with addBatch()

I have got the following query

public String strQuery = "insert into tt1 (i,j,k)values (?,?, (select notification_state from member where member_id = ? ) )";

which i execute in addbatch using the following code

public void executeQuery() throws Exception {

	PreparedStatement stmt = null;
	con.setAutoCommit(false);
	stmt = con.prepareStatement(strQuery);
	for (int i=10;i<=13;i++)
	{
		stmt.setLong(1,11);
		stmt.setLong(2,i);
		stmt.setLong(3,i);
		stmt.addBatch();
	}
	stmt.executeBatch();
	con.commit();

}

This is what are the values of the inner query

 MEMBER_ID NOTIFICATION_STATE

---------- ------------------
        10                 14
        11                  0
        12                 13
        13                  6

and when i call the function executeQuery() these are results of the tt1 table

        I J K
---------- ---------- ----------

        11         10         14
        11         11         14
        11         12         14
        11         13         14

rather than

        I J K
---------- ---------- ----------

        11         10         14
        11         11          0
        11         12         13
        11         13          6

which means that it is executing the inner sub-query only for member_id 10 ,not for the remaining member_id(s) and uses the notification_State value of member_id 10 for the remaining member_id(s). if I use executeUpdate() rather than addBatch() it works fine.

I hope i am clear with the problem ?
any ideas ?

Thanks & Regards

~Parvinder Received on Wed Jan 23 2002 - 11:37:19 CET

Original text of this message