Issue in Derby Database while fetching CLOB datatype or while commiting the 
transaction.
----------------------------------------------------------------------------------------

                 Key: DERBY-4332
                 URL: https://issues.apache.org/jira/browse/DERBY-4332
             Project: Derby
          Issue Type: Bug
          Components: JDBC
    Affects Versions: 10.5.1.1
         Environment: Windows XP SP2, machine: core 2 duo processor, 2GM 
primary mem.
            Reporter: baba shinde
            Priority: Critical


I am using Derby database for my application where auto commit on connection is 
set to false and I am doing the manual commit after every database update 
calls. In my application I am using CLOB data type to store the large string 
data in table column. And there are couples of test cases written to ensure the 
database working, but it has found very weird/inconsistent behavior of database 
either while fetching the data or while deleting the fetched data from database 
table. Probability of passing the test cases is 50 %( half of the time test 
cases fails and half of the time all test cases cleanly passes through)
Inconsistent behavior in the sense: every time code fails for either of the 
exception given below:

1) This exception occurs while removing the record from database.
Exception in thread "TestHandler-2-thread-1" 
java.lang.ArrayIndexOutOfBoundsException: -1
at org.apache.derby.client.net.Request.popMark(Unknown Source)
at org.apache.derby.client.net.Request.updateLengthBytes(Unknown Source)
at org.apache.derby.client.net.NetStatementRequest.buildEXCSQLSTT(Unknown 
Source)
at org.apache.derby.client.net.NetStatementRequest.writeExecute(Unknown Source)
at org.apache.derby.client.net.NetPreparedStatement.writeExecute_(Unknown 
Source)
at org.apache.derby.client.am.PreparedStatement.writeExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeX(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.execute(Unknown Source)

code snippet for the same is:
try {
      removeMessageStmt.setString(1, messageId);
      removeMessageStmt.execute();
      connection.commit();
    } catch (SQLException e) {
      try {
        connection.rollback();
      } catch (SQLException tx) {
        log.error("Failed to rollback the transaction", tx);
      }
  }
where removeMessageStmt is the prepared statement initialize at start.

2) java.sql.SQLNonTransientConnectionException: No current connection. 
Exception in connection.rollback()
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown 
Source) [derbyclient.jar:na]
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) 
[derbyclient.jar:na]
at org.apache.derby.client.am.Connection.rollback(Unknown Source) 
[derbyclient.jar:na]
at 
org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:328)
 [commons-dbcp-1.2.2.jar:1.2.2]

Caused by: org.apache.derby.client.am.SqlException: No current connection.
at org.apache.derby.client.am.Connection.checkForClosedConnection(Unknown 
Source) [derbyclient.jar:na]
... 20 common frames omitted

Caused by: java.sql.SQLNonTransientConnectionException: A network protocol 
error was encountered and the connection has been terminated: A PROTOCOL Data 
Stream Syntax Error was detected.  Reason: 0x2,644. Plaintext connection 
attempt to an SSL enabled server?
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown 
Source) [derbyclient.jar:na]
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) 
[derbyclient.jar:na]
at org.apache.derby.client.am.PreparedStatement.execute(Unknown Source) 
[derbyclient.jar:na]
at 
org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
 [commons-dbcp-1.2.2.jar:1.2.2]

I ran the test cases on SSL enabled connection but eror still exists. 

3) some times it gives throws an exception while while fetching the CLOB data 
from database tables.   
The exception 'java.sql.SQLException: The locator that was supplied for this 
CLOB/BLOB is invalid' was thrown while evaluating an expression.
You cannot invoke other java.sql.Clob/java.sql.Blob methods after calling the 
free() method or after the Blob/Clob's transaction has been committed or rolled 
back. 
this occurs even if I am using connection with auto commit false and committing 
on connection before result set is closed. code snippet for the same is:

    String str = "";
    getMessageStmt.setString(1, messageId);
     ResultSet resultSet = getMessageStmt.executeQuery();
     Clob clob = null;
     if (resultSet.next()) {
        clob = resultSet.getClob(1);
        try {
          str  = clobStringConversion(clob);
        } catch (IOException e) {
          throw new SQLException("Failed to convert CLOB to String.", e);
        }
      } else {
        log.info("No record found for the messageId: " + messageId);
        return null;
      }
      connection.commit();
      resultSet.close();
    
where *getMessageStmt is the preparedStatement initialized at start of 
application

I appreciate any help or pointers you can provide!

Thanks and Regards,
Baba



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to