You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Camel Guy (JIRA)" <ji...@apache.org> on 2014/11/10 22:27:34 UTC

[jira] [Commented] (CAMEL-7803) DefaultJdbcPrepareStatementStrategy Iterator fails on null value inserts

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

Camel Guy commented on CAMEL-7803:
----------------------------------

I appreciate that this is fixed. I spent the past 48 hours trying to figure this out. Eventually I found this JIRA and switched to 2.14.1-SNAPSHOT. When will 2.14.1 be released? I'm OK but I thought I would add my two cents about the severity of this problem especially for newbies. This was a killer as the error message implies that it's user error.

> DefaultJdbcPrepareStatementStrategy Iterator fails on null value inserts
> ------------------------------------------------------------------------
>
>                 Key: CAMEL-7803
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7803
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jdbc
>    Affects Versions: 2.13.2
>            Reporter: Nathan Wray
>            Assignee: Willem Jiang
>             Fix For: 2.12.5, 2.13.3, 2.14.1, 2.15.0
>
>         Attachments: 7803-patch.txt
>
>
> The iterator returned by createPopulateIterator in DefaultJdbcPrepareStatementStrategy incorrectly uses a next value of "null" to identify when it has run out of parameters.  This fails when the parameter map intentionally contains a name with a null value, which is the case when some columns in an insert should be set to null.  The attached pull request adds an explicit preFetch flag and relies on the done flag, avoiding the incorrect overloading of (next==null) to indicate completion.
> The iterator reports "hasNext() == false" when it encounters a map value of null.  This happens when using the map header JDBC_PARAMETERS = "CamelJdbcParameters" to insert null values with a prepared statement.  The Iterator ends prematurely when it reaches a parameter name with a null value.  
> For example, passing in a map where the 3rd parameter of 19 has a value of null causes the following exception to be thrown:
> java.sql.SQLException: Number of parameters mismatch. Expected: 19, was:2
>         at org.apache.camel.component.jdbc.DefaultJdbcPrepareStatementStrategy.populateStatement(DefaultJdbcPrepareStatementStrategy.java:137)
>         at org.apache.camel.component.jdbc.JdbcProducer.doCreateAndExecuteSqlStatementWithHeaders(JdbcProducer.java:133)
>         at org.apache.camel.component.jdbc.JdbcProducer.createAndExecuteSqlStatement(JdbcProducer.java:116)
>         at org.apache.camel.component.jdbc.JdbcProducer.processingSqlBySettingAutoCommit(JdbcProducer.java:85)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)