0

这是我的 Java DSL 路线:

        from("seda:singlePersonChannel")
    .log(LoggingLevel.INFO, "Person bean: ${body}")
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            Person person = exchange.getIn().getBody(Person.class);
            exchange.getOut().setBody(person.toSqlMap());
        }
    })
    .log(LoggingLevel.INFO, "Inserting into PERSON values: ${body}")
    .to("sql:INSERT INTO person (given_name, family_name) VALUES " +
    ":#givenName, :#familyName");

控制台显示格式正确的 DML:

Sql = INSERT INTO person (given_name, family_name) VALUES :1 , :2 , OriginalSql = INSERT INTO person (given_name, family_name) VALUES ?, ?, Error Msg = ORA-00947: not enough values

两个绑定变量都有值,所以空值不是问题:

15:20:58.622 INFO  [Camel (camel-1) thread #1 - seda://singlePersonChannel][route2] Person bean: Person{givenName=Given Name -593520961, familyName=Family Name 1883898232}
15:20:58.622 INFO  [Camel (camel-1) thread #1 - seda://singlePersonChannel][route2] Inserting into PERSON values: {givenName=Given Name -593520961, familyName=Family Name 1883898232}

然而甲骨文正在回归:

ORA-00947: not enough values

为了完整起见,我的配置是:

    <!-- the JDBC data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@DB-SVR-1:1521:DEV112A" />
    <property name="username" value="integration" />
    <property name="password" value="integration" />
</bean>

<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
    <property name="dataSource" ref="dataSource" />
</bean>

原始语句有 15 列和值,并且给出了相同的错误。顺便说一句,所有表列都可以为空。

4

1 回答 1

1

这是因为 的语法VALUES,值应该用括号括起来()

VALUES ?, ?

所以,应该是

.log(LoggingLevel.INFO, "Inserting into PERSON values: ${body}")
.to("sql:INSERT INTO person (given_name, family_name) VALUES(" +
":#givenName, :#familyName)");
于 2017-09-27T15:31:03.103 回答