[ 
https://issues.apache.org/jira/browse/DERBY-6214?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13685889#comment-13685889
 ] 

Mamta A. Satoor commented on DERBY-6214:
----------------------------------------

Just to recap, in this jira, we are trying to fix 
PreparedStatement.setObject(int, Object, Types.CLOB) when Object is of type 
String and that String object is less than or equal to 10922 characters. The 2 
attached patches attempt to fix the problem by sending such Strings as String 
on the wire from client to server rather than stream(this matches the behavior 
for PreparedStatement.setString). If we decide to do the same for 
ResultSet.updateObject (since the code is shared by ResultSet.updateObject and 
PreparedStatement.setObject), it runs into following exception
.derbyTesting.functionTests.tests.jdbcapi.ParameterMappingTest)java.lang.ClassCastException:
 java.lang.String incompatible with java.sql.Clob 
        at 
org.apache.derby.client.net.NetStatementRequest.computeProtocolTypesAndLengths(NetStatementRequest.java:1462)
 
        at 
org.apache.derby.client.net.NetStatementRequest.buildSQLDTAcommandData(NetStatementRequest.java:545)
 
        at 
org.apache.derby.client.net.NetStatementRequest.writeExecute(NetStatementRequest.java:162)
 
        at 
org.apache.derby.client.net.NetPreparedStatement.writeExecute_(NetPreparedStatement.java:156)
 
        at 
org.apache.derby.client.am.ClientResultSet.writeUpdateRow(ClientResultSet.java:4357)
 
        at 
org.apache.derby.client.am.ClientResultSet.positionToCurrentRowAndUpdate(ClientResultSet.java:4098)
 
        at 
org.apache.derby.client.am.ClientResultSet.updateRowX(ClientResultSet.java:3651)
 
        at 
org.apache.derby.client.am.ClientResultSet.updateRow(ClientResultSet.java:3555) 
        at 
org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMappingTest.testDerby6214updateXXX(ParameterMappingTest.java:439)
 

I have been looking at this exception and it looks like when dealing with 
ResultSet.updateObject on a CLOB column, we have coded everywhere to look for 
Clob column. I tried changing the offending code line in the stack trace above 
and ran into same exception again at a different part of the code as shown below
java.lang.ClassCastException: java.lang.String incompatible with java.sql.Clob
        at 
org.apache.derby.client.net.NetStatementRequest.buildEXTDTA(NetStatementRequest.java:1050)
        at 
org.apache.derby.client.net.NetStatementRequest.writeExecute(NetStatementRequest.java:168)
        at 
org.apache.derby.client.net.NetPreparedStatement.writeExecute_(NetPreparedStatement.java:156)
        at 
org.apache.derby.client.am.ClientResultSet.writeUpdateRow(ClientResultSet.java:4368)
        at 
org.apache.derby.client.am.ClientResultSet.positionToCurrentRowAndUpdate(ClientResultSet.java:4109)
        at 
org.apache.derby.client.am.ClientResultSet.updateRowX(ClientResultSet.java:3662)
        at 
org.apache.derby.client.am.ClientResultSet.updateRow(ClientResultSet.java:3566)
        at 
org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMappingTest.testDerby6214updateXXX(ParameterMappingTest.java:439)

Fixing that by to accomodate String rather than Clob at this place resulted in 
same exception in another place. So I do not think we can avoid using a Clob 
object for ResultSet.updateObject for a CLOB column easily. I am looking at 
intercepting the String object from CrossConverts.setObject for 
ResultSet.updateObject and see if we can fix the problem that way rather than 
having a special case in highly reused code in CrossConverts.setObject. 

Additionally, I put println in CrossConverts.setObject where we see if we are 
dealing with a String less than or equal to 10922 characters for a CLOB object 
and ran existing junit and derbyall tests and found that this code gets called 
only by ParameterMappingTest(by the new junit test that I have added in my 
codeline) and by existing junit test in UpdatableResultSetTest. So, atleast 
from the test runs, it looks like the suggested code changes in the 2 patches 
are used only by ResultSet.updateObject  and PreparedStatement.setObject
                
> PreparedStatement.setObject(int, Object, Types.CLOB) fail with DerbyNet
> -----------------------------------------------------------------------
>
>                 Key: DERBY-6214
>                 URL: https://issues.apache.org/jira/browse/DERBY-6214
>             Project: Derby
>          Issue Type: Bug
>    Affects Versions: 10.8.3.0, 10.9.1.0
>            Reporter: Rong Qu
>            Assignee: Mamta A. Satoor
>         Attachments: Derby6214.java, DERBY6214_patch1_diff.txt, 
> DERBY6214_patch1_stat.txt, DERBY6214_patch2_diff.txt, Derby6214_setup.sql, 
> Derby6214_ver2.java, derby.log, DerbyNet_client_test.sql
>
>
> The issue is specific to the DerbyNet client driver, and doesn't seem to 
> occur using embedded Derby.
>  "PreparedStatement.setObject(int, Object, Types.CLOB)". It seems to be a 
> problem updating a CLOB column with a parameterized value using the DerbyNet 
> client driver, and if the update SQL ends up updating more than one row. I 
> attached a simple test case that just uses JDBC to reproduce the error. The 
> exception looks like this:
> org.apache.derby.client.am.BatchUpdateException: Non-atomic batch failure.  
> The batch was submitted, but at least one exception occurred on an individual 
> member of the batch. Use getNextException() to retrieve the exceptions for 
> specific batched elements.
>     at org.apache.derby.client.am.Agent.endBatchedReadChain(Unknown Source)
>     at 
> org.apache.derby.client.am.PreparedStatement.executeBatchRequestX(Unknown 
> Source)
>     at org.apache.derby.client.am.PreparedStatement.executeBatchX(Unknown 
> Source)
>     at org.apache.derby.client.am.PreparedStatement.executeBatch(Unknown 
> Source)
>     ...
> Caused by: org.apache.derby.client.am.SqlException: Error for batch element 
> #0: An unexpected exception was thrown
>     at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
>     at 
> org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown 
> Source)
>     at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown 
> Source)
>     at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
>     at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown 
> Source)
>     at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown 
> Source)
>     ... 4 more
> Caused by: org.apache.derby.client.am.SqlException: Error for batch element 
> #0: Java exception: 'Stream has already been read and end-of-file reached and 
> cannot be re-used.: java.io.EOFException'.
>     at org.apache.derby.client.am.SqlException.<init>(Unknown Source)
>     at org.apache.derby.client.am.SqlException.<init>(Unknown Source)
>     ... 10 more

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to