使用sql server的Mule 3 JDBC端点异常

时间:2012-05-21 17:32:52

标签: sql-server-2008 jdbc mule

我正在尝试使用Mule JDBC出站端点将String插入SQL Server数据库。查询是:

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

当有效负载位于select语句的where子句中时,以及当我硬编码值代替有效负载表达式时,查询有效。但是,它与上面列出的插入语句失败了。我已经包含了下面的例外以及flow xml配置。任何建议/帮助将不胜感激!

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)

这是配置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 个答案:

答案 0 :(得分:2)

当我删除单引号时,它对我有用:

#[payload:java.lang.String]

答案 1 :(得分:1)

也许您需要将#[payload:java.lang.String]括在单引号中?您可以看到它尝试发出查询:

INSERT INTO ife VALUES (?, 0);

哪个不起作用。

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