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".