Is the reason for your design that you have set your connection to
SERIALIZABLE and that you are not using Oracle (maybe DB2 or SQLServer)?
Your code should work as intended.

There may however be a portability issue. Some appservers may require you to
use XA caonnections within a JTA transaction. In that case, you will have to
use an XA datasource (or XA connection pool, depending of your appserver
vendor) within the JTA transaction and a none-XA datasource for the read
operation, which would break your code.

/Johan



Den 2003-03-26 07.33, skrev "Siju Mathew" <[EMAIL PROTECTED]>:

> Hi All,
>
> I got a code block which looks like this
>
>
> // please ignore the syntax
>
> Connection conn = null;
> PreparedStatement pstmt = null
> ResultSet rs = null;
>
> try {
>
>                    // I may need to move the prepareStatement and
> getConnection call inside the
> // while
> loop
> conn = getConnection();
> pstmt = conn.prepareStatement(query);
>
> while(loopCondition){
>
>  rs = pstmt.executeQuery();
>  while(rs.next()){
>
>    // do something
>       dataObject.add(rs.getXXX(1));
>
>  } // end rs loop
>
> //         I need to get a new connection ( inside the transaction ) for
> transaction to work
>          cleanUpConnection()  // so i clean up the previous connections and
> statement
>       //transaction begin
>               // LABEL 1
>          conn = getConnection();
>          anotherObject.save(dataObject, conn)
>        cleanUpConnection();
>       // transation commit
>
> } // end loopCondition
>
> }finally{
>  cleanUpConnection();
> }
>
>
> At LABEL 1 I need to get a new connection. Since I don't want the same thread
> to keep more than one connection, I need to close the previous connection
> object. When closing the connection, I also need to close the result set and
> the prepared statement associated with that connection.
>
> This will force me to move the getConnection() and prepareStatement() call to
> inside the while loop. So for each iteration im preparing the statement.
>
> How to handle this condition. I don't want my select and save in the same
> transaction. I don't want the same thread to hold two transactions.
>
> Will the application server ensure that I get the same PreparedStatement in
> each iteration. I remember reading that it does. I'm using UserTransaction
> object to manage the transaction.
>
> Is there any other way I can do this ?.
>
> Thanks in advance
>
> --
> Siju C. Mathew
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to