4
votes

I am trying to insert a String into a SQL Server database using Mule JDBC outbound endpoint. The query is:

INSERT INTO ife VALUES (#[payload:java.lang.String], 0)

The query works when the payload is in a where clause of a select statement and when I hardcode values in place of the payload expression. However, it fails miserably with insert statements like the one listed above. I have included the exception below as well as the flow xml configuration. Any suggestions/help would be greatly appreciated!

ERROR 2012-05-21 11:37:00,122 [[ife].IFE_InboundFlow1.stage1.02]     org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to route event via endpoint:     DefaultOutboundEndpoint{endpointUri=jdbc://insert, connector=JdbcConnector
{
  name=Database__JDBC_
  lifecycle=start
  this=11e5f
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=true
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
,  name='endpoint.jdbc.insert', mep=ONE_WAY, properties={queryTimeout=-1,     queries=merged: {insert=INSERT INTO ife VALUES (#[payload:java.lang.String], 0)}},     transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0},     deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000,     endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type:     String
Code                  : MULE_ERROR-42999
--------------------------------------------------------------------------------
Exception stack is:
1. com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '?'.(SQL     Code: 0, SQL State: + null) (com.microsoft.sqlserver.jdbc.SQLServerException)
  com.microsoft.sqlserver.jdbc.SQLServerException:190 (null)
2. com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '?'. Query:     INSERT INTO ife VALUES (?, 0) Parameters: [30076](SQL Code: 0, SQL State: +     null) (java.sql.SQLException)
  org.apache.commons.dbutils.QueryRunner:540 (null)
3. Failed to route event via endpoint:     DefaultOutboundEndpoint{endpointUri=jdbc://insert, connector=JdbcConnector
{
  name=Database__JDBC_
  lifecycle=start
  this=11e5f
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=true
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
,  name='endpoint.jdbc.insert', mep=ONE_WAY, properties={queryTimeout=-1, queries=merged: {insert=INSERT INTO ife VALUES (#[payload:java.lang.String], 0)}}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: String (org.mule.api.transport.DispatchException)
  org.mule.transport.AbstractMessageDispatcher:107 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '?'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:426)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:1532)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Here's the configuration xml:

<spring:beans>
        <spring:bean id="Bean" name="Bean" class="org.enhydra.jdbc.standard.StandardDataSource" doc:name="Bean">
            <spring:property name="driverName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <spring:property name="url" value="jdbc:sqlserver://localhost:1433;instanceName=SQLEXPRESS;databaseName=test;user=test;password=test;"/>
        </spring:bean>
    </spring:beans>
<jdbc:connector name="Database__JDBC_" dataSource-ref="Bean" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database (JDBC)"/>
<flow name="test">
    <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="insert" responseTimeout="10000" mimeType="text/plain" queryTimeout="-1" connector-ref="Database__JDBC_" doc:name="Database (JDBC)">
                                <jdbc:query key="insert" value="INSERT INTO ife VALUES (#[payload:java.lang.String], 0)"/>
                            </jdbc:outbound-endpoint>
</flow>
2
Could you set -Dmule.verbose.exceptions=true and also increase log verbosity to DEBUG and share the extended log? Also what Mule version do you use? Finally, you do you call the test flow?David Dossot
I'm using mule 3.1.1 ide plugin for eclipse indigo service release 2. As for setting the verbosity... I have the log4j.properties set to DEBUG already so I'm not really sure what you mean at this point. Also, I run the flow as a mule application in eclipse. I am still new to Mule, so bear with me.user1408370
Cool, so you should see lots of DEBUG messages in the console when you invoke the test flow (how do you do that btw?). Can you post these log entries?David Dossot
I just right click the flow and run as a mule application, keep in mind the above xml config is not complete as I only posted relevant portions that were related to the jdbc configuration. The log currently just shows a ton of INFO, a few WARNs, and the one ERROR. I have it set to DEBUG in the log4j.properties file in the mule home directory, but apparently that's not working. Do you know how I set '-Dmule.verbose.exceptions=true'?user1408370
Mmmh I guess log4j.properties is ignored then, what I was trying to get at is having the JDBC connector log the issued SQL statements and potentially other relevant DEBUG messages to help us track the issue. You can set JVM parameters in the "Run Configurations" Eclipse menu.David Dossot

2 Answers

2
votes

It worked for me when I removed the single quote:

#[payload:java.lang.String]
1
votes

Perhaps you need to enclose the #[payload:java.lang.String] in single quotes? You can see its trying to issue the query:

INSERT INTO ife VALUES (?, 0);

Which isn't going to work.

INSERT INTO ife VALUES ('#[payload:java.lang.String]', 0)?