[英]Mule 3 JDBC endpoint exception with sql server
I am trying to insert a String into a SQL Server database using Mule JDBC outbound endpoint. 我试图使用Mule JDBC出站端点将String插入SQL Server数据库。 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. 当有效负载位于select语句的where子句中并且我使用硬编码值代替有效负载表达式时,查询将起作用。 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. 我已经包含了下面的例外以及flow xml配置。 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: 这是配置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>
删除单引号时,它对我有用:
#[payload:java.lang.String]
Perhaps you need to enclose the #[payload:java.lang.String] in single quotes? 也许您需要将#[payload:java.lang.String]括在单引号中? 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)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.