Hi,
I am using MaxDB with JBoss 3.2.6. I have a problem; suddenly my
PreparedStatements are being closed. (SAP DBTech JDBC: Object is
closed.). Here is detailed information.
I am getting connection that I hold oppened. Initially I create several
Prepared Statements to do my logic stuff. I am querying for “process”
(let’s call them tat) that I have to remove. I have to remove them and
all of their resources. I am removing each process (and its resources in
different transaction). I start open transaction, remove the first
process and then commit the transaction. Then I open new transaction and
I try to remove the next process, and here is the exception that I am
getting. (com.sap.dbtech.jdbc.exceptions.ObjectIsClosedException: SAP
DBTech JDBC: Object is closed)
Here is a snippet of that exception.
10:49:00,281 ERROR [ReorgImpl] [:removeProcessInstances]Exception while
deleteing resources of process instance:
58210f21-fae4-11da-b374-7a2f0a0a12ac occures!
com.sap.dbtech.jdbc.exceptions.ObjectIsClosedException: SAP DBTech JDBC:
Object is closed.
at com.sap.dbtech.jdbc.ConnectionItem.assertOpen(ConnectionItem.java:62)
at
com.sap.dbtech.jdbc.CallableStatementSapDB.setString(CallableStatementSapDB.java:2180)
at
com.sap.dbtech.jdbcext.ClientPreparedStatementSapDB.setString(ClientPreparedStatementSapDB.java:612)
at
org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setString(Unknown
Source)
at com.seeb.engine.reorg.ReorgImpl.deleteAttachments(ReorgImpl.java:747)
at com.seeb.engine.reorg.ReorgImpl.deleteResources(ReorgImpl.java:674)
at
com.seeb.engine.reorg.ReorgImpl.removeProcessInstances(ReorgImpl.java:611)
Here is a snippet of my code that I execute
public void reorg(SessionContext ctx)
{
String errorMsg = "";
userTran = ctx.getUserTransaction();//get User transaction
try
{
initSessionState(); //here I create my prepared statements
removeProcessInstances();
}
catch (Exception e)
{
logger.error("[:reorg]Exception occures during invokation! {0}",
errorMsg, e);
}
finally
{
releaseSessionState(); //here I close connection (return to pool) and
close Prepared statements
}
}//end of reorg
private void removeProcessInstances() throws Exception
{
Statement stmt = null;
ResultSet rs = null;
ArrayList toDeleteList = new ArrayList();
….. fill toDelete List……..
try
{
for (int i = 0; i < toDeleteList.size(); i++)
{
ReorgProcess reorgProcess = (ReorgProcess)toDeleteList.get(i);
String id = reorgProcess.getProcessId();
String transctionId = reorgProcess.getTransactionId();
int state = reorgProcess.getState();
try
{
userTran.begin(); //start transaction
deleteResources(id, transctionId, state);
userTran.commit(); //commit transaction
}
catch (Exception eTrans)
{
logger.error("[:removeProcessInstances]Exception while deleteing
resources of process instance: {0} occures! ", id, eTrans);
userTran.rollback();
//increase the count of process that failed to delete
failed++;
}
}//end loop for over instances
}
finally
{
if (rs != null)
{
rs.close();
}
if (stmt != null)
{
stmt.close();
}
}
}// end removeProcessInstances()
private void deleteResources(String procID, String transactionIdArg, int
stateArg) throws Exception
{
//delete attachments, attachToProc records and diaf reseources
deleteAttachments(procID);
….. and more ….
}//end deleteResources
private void deleteAttachments(String procID)
throws SQLException, RemoteException
{
ArrayList attachmentsIDs = new ArrayList();
ResultSet attachResult = null;
ResultSet attachProcesResSet = null;
ResultSet rs = null;
try
{
//get all attachments id-s to be able to remove diaf resources
if (conRemove.isClosed())
{
logger.info("----------------------- conRemove is clossed
----------------------------------");
}
else
{
logger.info("+++++++++++++++++++++++ conRemove is not clossed
+++++++++++++++++++++++++++++++");
}
Connection conn = selectAttachmetsStmt.getConnection();
if (conn != null)
{
if (conn.isClosed())
{
logger.info("----------------------- con is clossed
----------------------------------");
}
else
{
logger.info("+++++++++++++++++++++++ con is not clossed
+++++++++++++++++++++++++++++++");
}
}
selectAttachmetsStmt.setString(1, procID); //FAILS HERE on the second run
attachResult = selectAttachmetsStmt.executeQuery();
while (attachResult.next())
{
attachmentsIDs.add(attachResult.getString(1));
}
//get infromation for latter clean of attachToProc cache
if (useAttachmentCache)
{
//find all the attachments to process for this process
attachToProcStmt.setString(1, procID);
attachProcesResSet = attachToProcStmt.executeQuery();
while (attachProcesResSet.next())
{
//find the attachment id for this attachment to proces
String attachId = attachProcesResSet.getString(1);
//create new object and put it to set for latter remove from the cache
AttachmentToProcess attachToProc = new AttachmentToProcess(attachId,
procID);
attachToProcSet.add(attachToProc);
}
}
//delete references for the current process for its attachments in the
//tAttachProc
attachProcStatement.setString(1, procID);
attachProcStatement.execute();
for (int i = 0; i < attachmentsIDs.size(); i++)
{
String attachId = (String)attachmentsIDs.get(i);
//remove attachment if there is no reference in tAttachProc table
attachProcSelectStmt.setString(1, attachId);
rs = attachProcSelectStmt.executeQuery();
boolean hasReferenceInAttachProc = false;
if ( rs.next())
{
//should NOT delete attachment - there is reference in
//attacmentProc table
hasReferenceInAttachProc = true;
}
….. and more …..
}
}
finally
{
if (attachResult != null)
{
attachResult.close();
}
if (attachProcesResSet != null)
{
attachProcesResSet.close();
}
if (rs != null)
{
rs.close();
}
}
}//end of deleteAttachments
I am wondering while the PreparedStatement is closed? I put some ugly
logging to check if the connection is closed. But it is not. Here is
snippet before the exception.
10:49:00,171 INFO [ReorgImpl] +++++++++++++++++++++++ conRemove is not
clossed +++++++++++++++++++++++++++++++
10:49:00,171 INFO [ReorgImpl] +++++++++++++++++++++++ con is not clossed
+++++++++++++++++++++++++++++++
THIS WAS THE FIRST EXECUTION (First transaction)
10:49:00,281 INFO [ReorgImpl] +++++++++++++++++++++++ conRemove is not
clossed+++++++++++++++++++++++++++++++
10:49:00,281 INFO [ReorgImpl] +++++++++++++++++++++++ con is not clossed
+++++++++++++++++++++++++++++++
THIS IS THE SECOND TRANSACTION. As you see the connection is not closed
but …
10:49:00,281 ERROR [ReorgImpl] [:removeProcessInstances]Exception while
deleteing resources of process instance:
58210f21-fae4-11da-b374-7a2f0a0a12ac occures!
com.sap.dbtech.jdbc.exceptions.ObjectIsClosedException: SAP DBTech JDBC:
Object is closed.
As you see the connection is not closed. It seems that this is something
in the jdbc driver. That’s why I am asking for your support. I dig a
little in the JDBC driver. Where the exception occurs at
com.sap.dbtech.jdbc.ConnectionItem.assertOpen(ConnectionItem.java:62)
Here is a snippet of the driver.
final protected void assertOpen () throws SQLExceptionSapDB {
if (this.connection == null
|| this.connection.session == null) {
throw new ObjectIsClosedException (this);
}
}
Connection differs from null, but this connection.session was null (If
this is telling you something).
So this is my problem. In the end here is my environment. Windows XP
+SP2. JBoss 3.2.6 (I can send you my data source file if this will help
you). MaxDB: maxdb-all-win-32bit-i386-7_6_00_16. I used the latest
available jdbc driver: sapdbc-7_6_00_24_5241.jar
I would like to note that the code I pasted above works perfect on
Oralce 10 and MS SQL SERVER 2000.
Best Regards, Zhivko
--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]