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>
-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 thetest
flow? – David Dossottest
flow (how do you do that btw?). Can you post these log entries? – David Dossot