4

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

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

当有效负载位于 select 语句的 where 子句中并且当我硬编码值代替有效负载表达式时,查询将起作用。但是,对于上面列出的插入语句,它会惨遭失败。我已经包含了下面的异常以及流 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>
4

2 回答 2

2

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

#[payload:java.lang.String]
于 2012-11-02T12:54:31.530 回答
1

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

INSERT INTO ife VALUES (?, 0);

这是行不通的。

INSERT INTO ife VALUES ('#[payload:java.lang.String]', 0)?
于 2012-05-30T17:20:26.227 回答