如何使用WSO2ESB或WSO2DSS将动态字段查询传递到数据库

时间:2013-01-24 12:56:17

标签: wso2 wso2esb wso2dss

我想将查询传递给数据库以检索列。我使用ESB传递动态列我的配置就像这样

 <proxy xmlns="http://ws.apache.org/ns/synapse" name="dbl3" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">   <target>
         <inSequence>
            <property name="A" value="select e_name,e_address from emp where " scope="default" type="STRING"/>
            <property name="B" expression="//fieldname/text()" scope="default" type="STRING"/>
            <property name="C" expression="//fieldvalue/text()" scope="default" type="STRING"/>
            <property name="D" value="=" scope="default" type="STRING"/>
            <property name="E" expression="concat(get-property('A'),get-property('B'),get-property('D'),get-property('C'))" scope="default" type="STRING"/>
            <dblookup>
               <connection>
                  <pool>
                     <password>Youtility11</password>
                     <user>youtilitydba</user>
                     <url>jdbc:postgresql://localhost:5432/sample</url>
                     <driver>org.postgresql.Driver</driver>
                  </pool>
               </connection>
               <statement>
                  <sql>get-property('E')</sql>
                  <result name="ee" column="e_name"/>
               </statement>
            </dblookup>
            <log level="custom">
               <property name="AA" expression="get-property('A')"/>
               <property name="BB" expression="get-property('B')"/>
               <property name="CC" expression="get-property('C')"/>
               <property name="DD" expression="get-property('ee')"/>
               <property name="EE" expression="get-property('E')"/>
            </log>
         </inSequence>
         <outSequence>
                <send/>
             </outSequence>   </target>   <description></description> </proxy>

我的输出如下:

EE = select e_name,e_address from emp where e_address=thane
EE = select e_name,e_address from emp where e_no=5

根据输入值查询会生成,我该如何将上述查询传递给数据库? 我的错误是这样的:

[2013-01-24 14:22:32,743] ERROR - DBLookupMediator Error executing statement : get-property('E') against DataSource : jdbc:postgresql://localhost:5432/sample
org.postgresql.util.PSQLException: ERROR: syntax error at or near "get"
 Position: 1
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.synapse.mediators.db.DBLookupMediator.processStatement(DBLookupMediator.java:46)
    at org.apache.synapse.mediators.db.AbstractDBMediator.mediate(AbstractDBMediator.java:143)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:60)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:114)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:154)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:144)
    at org.apache.axis2.transport.http.util.RESTUtil.processXMLRequest(RESTUtil.java:89)
    at org.apache.synapse.transport.nhttp.util.RESTUtil.processPOSTRequest(RESTUtil.java:189)
    at org.apache.synapse.transport.nhttp.ServerWorker.processEntityEnclosingMethod(ServerWorker.java:411)
    at org.apache.synapse.transport.nhttp.ServerWorker.run(ServerWorker.java:268)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

1 个答案:

答案 0 :(得分:2)

我担心您无法使用“get-property”构造将SQL语句传递给DBLookup / DBReport介体的“<sql/>”元素。此外,我相信你要做的就是将变量传递给SQL查询。这样做的正确方法应该是使用WSO2数据服务服务器。请参阅WSO2 DSS [1]的文档,该文档通过为用户提供的丰富功能,为您提供有关如何使用它来实现数据操作任务的全面指南。

[1] http://docs.wso2.org/wiki/display/DSS301/WSO2+Data+Services+Server+Documentation