无法将值插入从Apache Camel中的XML文件获取的Oracle数据库

无法将值插入从Apache Camel中的XML文件获取的Oracle数据库,oracle,apache-camel,stringbuilder,Oracle,Apache Camel,Stringbuilder,我正在做一个将XML值插入Oracle数据库的概念验证。我在Java中使用StringBuilder插入值。我的背景是: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-ins

我正在做一个将XML值插入Oracle数据库的概念验证。我在Java中使用StringBuilder插入值。我的背景是:

    <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="
                     http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
                     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

              <bean id="dataSource" class="org.springframework.jdbc.datasource">
                <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
                <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:xe"/>
                <property name="username" value="system"/>
                <property name="password" value="1234"/>
              </bean>
             <bean id="orderToSQL" class="camel.project.camel.system.OrderToSQLBean" />
             <camelContext xmlns="http://camel.apache.org/schema/spring">
                <route>
               <from uri="file:src/data?noop=true"/>
                    <choice>
                        <when>
                            <xpath>/person/city = 'London'</xpath>
                            <log message="UK message"/>
                            <to uri="file:target/messages/uk"/>
                        </when>
                        <when>
                            <xpath>/person/city = 'Charleston'</xpath>
                            <log message="US message"/>
                            <to uri="bean:orderToSQL?method=toSql"/>
                        </when>
                        <otherwise>
                            <log message="Other message"/>
                            <to uri="file:target/messages/others"/>
                        </otherwise>
                    </choice>
                </route>
            </camelContext>
             </beans>
我正在打印stringbuilder获取的字符串。生成的查询语法与oracle数据库查询相同

String = insert into people(country, lastname, firstname, city) values ('US', 'Peeples', 'Kenneth', 'Charleston'); 

请帮我解决这个问题。我没有使用任何blueprint XML。

奇怪的是,您没有看到任何错误。选择和插入都有一个颤音分号;这是一个语句分隔符,无效。插入内容应为:

String = insert into people(country, lastname, firstname, city)
values ('US', 'Peeples', 'Kenneth', 'Charleston')
。。。没有分号。也从选择中删除一个,这也需要在中的
之前添加一个空格:

st.executeQuery("SELECT * from people");
您应该为这两个语句获取ORA-00911,所以它可能根本就没有尝试执行它们。您返回的是
sb
,但我不熟悉Camel,因此我不知道何时或是否有任何东西实际执行您返回的内容,或者您是否应该从
toSql()
方法中执行它


您还应该使用准备好的语句和绑定变量,而不是通过StringBuilder将固定值放入字符串中,但这稍微超出了问题的范围。不过,您应该仔细阅读SQL注入。

谢谢您的回复Alex Poole…您能提供一些代码来使用stringbuilder将数据插入oracle数据库吗。。
String = insert into people(country, lastname, firstname, city)
values ('US', 'Peeples', 'Kenneth', 'Charleston')
st.executeQuery("SELECT * from people");