Re: 40XD0: Container has been closed?

2012-11-04 Thread John English

On 03/11/2012 21:06, Katherine Marsden wrote:

This has the feel of two threads using the same Connection and one
commits or rolls back without coordination with the other. Typically
each thread should have it's own connection.  Do you have a separate
connection for each thread and if so, what is the isolation level?


No, each thread has its own connection. The situation is that tests can 
be run synchronously from a servlet, so a request comes in, a DB 
connection is created, the connection is used to do select * from tests 
where id=?, and the results go back immediately in the response and the 
DB connection is then closed. Alternatively, tests can be scheduled to 
run asynchronously, and there is a thread created at system startup with 
its own connection which loops waiting for notifications that a test has 
completed and then issues exactly the same query.


In the synchronous case it always works; in the asynchronous case it 
always fails. I've tried creating a new connection each time round the 
loop in the asynchronous case, but it makes no difference. Also if it 
were a thread contention issue I'd expect to see some timing-dependent 
behaviour, not total consistency.


The rest of the row can always be read (ints and varchars and suchlike), 
but the clob always fails. I've tried reading the clob first; same 
thing. The isolation level is default, but in any case it happens even 
when nothing else is going on; I start an asynchronous test on my 
development rig with no other users, and then sit back and wait. It 
consistently hits the breakpoint I've set on the exception handler. This 
also points to it not being a thread contention problem.


One final thing: my fix (where I read the rest of the row in one query 
and the clob in another) uses the same connection for both queries.


So I'm totally baffled. Happy to have found a workaround but very 
annoyed that I don't understand why it works.


Thanks for your help,
--
John English


40XD0: Container has been closed?

2012-11-03 Thread John English
Suddenly for no discernable reason I'm getting this error (stacktrace 
below) while using getString() to read from a clob, the contents of 
which is only about 60K in length. I also have a testing interface which 
lets me type in raw SQL, and which also uses getString() to read the 
columns from the result set, and issuing the same query that producesd 
this error works fine from there.


The only thing I can think of that's different when it fails is that it 
is running in a background thread which waits for entries to appear in a 
work queue and then processes them. I can't see what difference that 
would make, though...


The Derby version is 10.8.1.2 (1095077) running on Java 1.7.0_03-b05.

Can anyone tell me why this might be happening please?

---
java.sql.SQLException: An IOException was thrown when reading a 
'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
Source)

at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at utils.Results.getString(Results.java:169)
at utils.TestDetails.init(TestDetails.java:202)
at utils.TestServer.run(TestServer.java:95)
Caused by: java.sql.SQLException: An IOException was thrown when reading 
a 'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)

... 10 more
Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
Container has been closed.: java.io.IOException'.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)

... 7 more
Caused by: java.io.IOException: ERROR 40XD0: Container has been closed.
	at 
org.apache.derby.impl.store.raw.data.OverflowInputStream.fillByteHolder(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream.read(Unknown 
Source)

at java.io.DataInputStream.read(Unknown Source)
at org.apache.derby.iapi.types.SQLClob.readExternal(Unknown Source)
at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
... 5 more
Caused by: ERROR 40XD0: Container has been closed.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.checkOpen(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown 
Source)

... 10 more
java.sql.SQLException: An IOException was thrown when reading a 
'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
Source)

at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at utils.Results.getString(Results.java:169)
at utils.TestDetails.init(TestDetails.java:183)
at utils.TestServer.run(TestServer.java:95)
Caused by: java.sql.SQLException: An IOException was thrown when reading 
a 'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)

... 10 more
Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
Container has been closed.: java.io.IOException'.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source

Re: 40XD0: Container has been closed?

2012-11-03 Thread John English

On 03/11/2012 13:15, John English wrote:

Suddenly for no discernable reason I'm getting this error (stacktrace
below) while using getString() to read from a clob, the contents of
which is only about 60K in length.


Something interesting: I've fixed the problem (i.e. made it go away). 
I'm always reading a single row with the query, so I've changed my code 
from:

  * execute the query
  * take all row elements and store them in variables
  * close the result set etc.
to
  * execute the query
  * take all row elements except the CLOB and store them in variables
  * close the result set etc.
  * execute the same query
  * take only the CLOB and store it in a variable
  * close the result set etc.
and that made the problem go away.

Naturally, I'm somewhat dissatisfied with this!
Any ideas welcomed...

TIA,
--
John English


Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-16 Thread Dinesh Bajaj
I used ByteArrayOutputStream as you suggested, and the problem vanished. Thank 
you!!

-Dinesh

--- On Tue, 16/2/10, Dinesh Bajaj dinesh.ba...@ymail.com wrote:

From: Dinesh Bajaj dinesh.ba...@ymail.com
Subject: Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.
To: Derby Discussion derby-user@db.apache.org
Date: Tuesday, 16 February, 2010, 10:16 AM


Hi Bryan,

Good idea. Having not worked much with streams before, this idea didn't strike 
me, or I was rather unaware about this possibility. I will try to implement 
this, and let you know whether this worked or not.

Thanks,
Dinesh
--- On Tue, 16/2/10, Bryan Pendleton bpendle...@amberpoint.com wrote:

From: Bryan Pendleton bpendle...@amberpoint.com
Subject: Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.
To: Derby Discussion derby-user@db.apache.org
Date: Tuesday, 16 February, 2010, 7:17 AM

            ResultSet rs = con.createStatement().executeQuery(
           
          select * from TABLE1);
            rs.next();
            InputStream is = rs.getBinaryStream(1);
                    long length = rs.getBlob(1).length();
             rs.close();
 
             con.setAutoCommit(false);
             ps = con.prepareStatement(update table1 set photo = ?);
             ps.setBinaryStream(1, is, length);
             ps.executeUpdate();

I think it's problematic to try to hold on to the stream after
you've closed the ResultSet.

What happens if you read the stream fully into memory (say,
 by
copying it into a ByteArrayOutputStream), before closing the
result set, and then use your in-memory byte array to provide
the data for the update into the other table?

thanks,

bryan






   
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.


  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
http://in.yahoo.com/

Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Donald McLean
When working with BLOBs and CLOBs, these sorts of errors are almost always
caused by committed transactions. Since most people don't expect to need a
transaction
 for a select, more often than not autocommit is set to TRUE and the select
commits as soon as it is executed. While this is fine for everything else,
it doesn't work for BLOB/CLOB fields. A BLOB/CLOB is only valid inside a
single transaction and the instant that transaction finished (commit or
rollback) the BLOB/CLOB goes poof.

Donald

On Mon, Feb 15, 2010 at 2:33 AM, Dinesh Bajaj dinesh.ba...@ymail.comwrote:

 I get the above error while executing the Update statement through a java
 application. The error occurs when the update statement involves a Blob
 field.

 I have ensured that input stream being given to setBinaryStream method is
 not closed and the length being given is also correct.

 Also, may I say that I can't find any source where I can readily find the
 detailed description of a Derby error and its possible causes. The reference
 documentation just cryptically says : Container has been closed. Now, what
 can be make out of this?



-- 
Family photographs are a critical legacy for
ourselves and our descendants. Protect that
legacy with a digital backup and recovery plan.

Join the photo preservation advocacy Facebook group:
http://www.facebook.com/home.php?ref=logo#/group.php?gid=148274709288


Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Dinesh Bajaj
Hi Donald,

Thanks for your reply.

I am afraid that I couldn't fully understood your reply. What could I 
understand, I tried to translate that into action by setting the 
conn.setAutoCommit(false) of the connection object before calling 
conn.preparedStatement(sql), and then calling calling conn.commit() after 
preparedStatement.executeUpdate(), but the exception still occurs.

Could you suggest what code change(s) should I make to fix this?

Regards,
Dinesh

--- On Mon, 15/2/10, Donald McLean dmclea...@gmail.com wrote:

From: Donald McLean dmclea...@gmail.com
Subject: Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.
To: Derby Discussion derby-user@db.apache.org
Date: Monday, 15 February, 2010, 6:45 PM

When working with BLOBs and CLOBs, these sorts of errors are almost always 
caused by committed transactions. Since most people don't expect to need a 
transaction
 for a select, more often than not autocommit is set to TRUE and the select 
commits as soon as it is executed. While this is fine for everything else, it 
doesn't work for BLOB/CLOB fields. A BLOB/CLOB is only valid inside a single 
transaction and the instant that transaction finished (commit or rollback) the 
BLOB/CLOB goes poof.


Donald

On Mon, Feb 15, 2010 at 2:33 AM, Dinesh Bajaj dinesh.ba...@ymail.com wrote:


I get the above error while executing the Update statement through a java 
application. The error occurs when the update statement involves a Blob field. 

I have ensured that input stream being given to setBinaryStream method is not 
closed and the length being given is also correct.


Also, may I say that I can't find any source where I can readily find the 
detailed description of a Derby error and its possible causes. The reference 
documentation just cryptically says : Container has been closed. Now, what 
can be make out of this?




-- 
Family photographs are a critical legacy for
ourselves and our descendants. Protect that
legacy with a digital backup and recovery plan.


Join the photo preservation advocacy Facebook group:
http://www.facebook.com/home.php?ref=logo#/group.php?gid=148274709288




  Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/

Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Kristian Waagan

On 15.02.10 14:15, Donald McLean wrote:

When working with BLOBs and CLOBs, these sorts of errors are almost always
caused by committed transactions. Since most people don't expect to need a
transaction
  for a select, more often than not autocommit is set to TRUE and the select
commits as soon as it is executed. While this is fine for everything else,
it doesn't work for BLOB/CLOB fields. A BLOB/CLOB is only valid inside a
single transaction and the instant that transaction finished (commit or
rollback) the BLOB/CLOB goes poof.
   


Dinesh,

What Donald says is very true, but we have had some bugs in this area.
If following Donald's advice doesn't help you, please post the relevant 
part of your code (preferably in a runnable state) and the full stack trace.



Regards,
--
Kristian


Donald

On Mon, Feb 15, 2010 at 2:33 AM, Dinesh Bajajdinesh.ba...@ymail.comwrote:

   

I get the above error while executing the Update statement through a java
application. The error occurs when the update statement involves a Blob
field.

I have ensured that input stream being given to setBinaryStream method is
not closed and the length being given is also correct.

Also, may I say that I can't find any source where I can readily find the
detailed description of a Derby error and its possible causes. The reference
documentation just cryptically says : Container has been closed. Now, what
can be make out of this?



 




Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Dinesh Bajaj
)
    at org.apache.derby.impl.store.raw.data.MemByteHolder.write(Unknown 
Source)
    at 
org.apache.derby.impl.store.raw.data.RememberBytesInputStream.fillBuf(Unknown 
Source)
    at org.apache.derby.impl.store.raw.data.StoredPage.logColumn(Unknown 
Source)
    at org.apache.derby.impl.store.raw.data.StoredPage.logRow(Unknown 
Source)
    at 
org.apache.derby.impl.store.raw.data.UpdateOperation.writeOptionalDataToBuffer(Unknown
 Source)
    at org.apache.derby.impl.store.raw.data.UpdateOperation.init(Unknown 
Source)
    at 
org.apache.derby.impl.store.raw.data.LoggableActions.actionUpdate(Unknown 
Source)
    at 
org.apache.derby.impl.store.raw.data.StoredPage.doUpdateAtSlot(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BasePage.updateAtSlot(Unknown 
Source)
    at 
org.apache.derby.impl.store.access.conglomerate.GenericConglomerateController.replace(Unknown
 Source)
    at org.apache.derby.impl.sql.execute.RowChangerImpl.updateRow(Unknown 
Source)
    at 
org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(Unknown 
Source)
    at org.apache.derby.impl.sql.execute.UpdateResultSet.open(Unknown 
Source)
    at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
    at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
Source)
    ... 6 more

--- On Mon, 15/2/10, Kristian Waagan kristian.waa...@sun.com wrote:

From: Kristian Waagan kristian.waa...@sun.com
Subject: Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.
To: Derby Discussion derby-user@db.apache.org
Date: Monday, 15 February, 2010, 7:41 PM

On 15.02.10 14:15, Donald McLean wrote:
 When working with BLOBs and CLOBs, these sorts of errors are almost always
 caused by committed transactions. Since most people don't expect to need a
 transaction
   for a select, more often than not autocommit is set to TRUE and the select
 commits as soon as it is executed. While this is fine for everything else,
 it doesn't work for BLOB/CLOB fields. A BLOB/CLOB is only valid inside a
 single transaction and the instant that transaction finished (commit or
 rollback) the BLOB/CLOB goes poof.
    

Dinesh,

What Donald says is very true, but we have had some bugs in this area.
If following Donald's advice doesn't help you, please post the relevant 
part of your code (preferably in a runnable state) and the full stack trace.


Regards,
-- 
Kristian

 Donald

 On Mon, Feb 15, 2010 at 2:33 AM, Dinesh Bajajdinesh.ba...@ymail.comwrote:

    
 I get the above error while executing the Update statement through a java
 application. The error occurs when the update statement involves a Blob
 field.

 I have ensured that input stream being given to setBinaryStream method is
 not closed and the length being given is also correct.

 Also, may I say that I can't find any source where I can readily find the
 detailed description of a Derby error and its possible causes. The reference
 documentation just cryptically says : Container has been closed. Now, what
 can be make out of this?



      




  Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/

Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Bryan Pendleton

   ResultSet rs = con.createStatement().executeQuery(
select * from TABLE1);
   rs.next();
   InputStream is = rs.getBinaryStream(1);

   long length = rs.getBlob(1).length();

rs.close();

con.setAutoCommit(false);
ps = con.prepareStatement(update table1 set photo = ?);
ps.setBinaryStream(1, is, length);
ps.executeUpdate();


I think it's problematic to try to hold on to the stream after
you've closed the ResultSet.

What happens if you read the stream fully into memory (say, by
copying it into a ByteArrayOutputStream), before closing the
result set, and then use your in-memory byte array to provide
the data for the update into the other table?

thanks,

bryan



Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-15 Thread Dinesh Bajaj

Hi Bryan,

Good idea. Having not worked much with streams before, this idea didn't strike 
me, or I was rather unaware about this possibility. I will try to implement 
this, and let you know whether this worked or not.

Thanks,
Dinesh
--- On Tue, 16/2/10, Bryan Pendleton bpendle...@amberpoint.com wrote:

From: Bryan Pendleton bpendle...@amberpoint.com
Subject: Re: 'ERROR 40XD0: Container has been closed.: java.io.IOException'.
To: Derby Discussion derby-user@db.apache.org
Date: Tuesday, 16 February, 2010, 7:17 AM

            ResultSet rs = con.createStatement().executeQuery(
                     select * from TABLE1);
            rs.next();
            InputStream is = rs.getBinaryStream(1);
                    long length = rs.getBlob(1).length();
             rs.close();
 
             con.setAutoCommit(false);
             ps = con.prepareStatement(update table1 set photo = ?);
             ps.setBinaryStream(1, is, length);
             ps.executeUpdate();

I think it's problematic to try to hold on to the stream after
you've closed the ResultSet.

What happens if you read the stream fully into memory (say, by
copying it into a ByteArrayOutputStream), before closing the
result set, and then use your in-memory byte array to provide
the data for the update into the other table?

thanks,

bryan




  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
http://in.yahoo.com/

'ERROR 40XD0: Container has been closed.: java.io.IOException'.

2010-02-14 Thread Dinesh Bajaj
Hi,

I get the above error while executing the Update statement through a java 
application. The error occurs when the update statement involves a Blob field. 

I have ensured that input stream being given to setBinaryStream method is not 
closed and the length being given is also correct.

Also, may I say that I can't find any source where I can readily find the 
detailed description of a Derby error and its possible causes. The reference 
documentation just cryptically says : Container has been closed. Now, what 
can be make out of this?

Regards,
Dinesh








  Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/