2014-06-07 75 views
0
帶參數的存儲過程

我已經......我使用的騾子JDBC和下面的配置,我主持使用騾子... web服務檢索MS SQL數據庫中數據的Web服務: -如何使用騾子

<context:property-placeholder location="classpath:conf/DBConnectionProp.properties"/> 
     <spring:beans> 
      <spring:bean id="DB_Source" name="DB_Source" class="org.enhydra.jdbc.standard.StandardDataSource"> 
       <spring:property name="url" value="${url}"/> 
       <spring:property name="driverName" value="${driverName}"/> 
      </spring:bean> 
      <spring:bean id="LookUp" name="LookUp" class="com.test.MainDataDAOImpl"> 
       <spring:property name="dataSource" ref="DB_Source"/> 
      </spring:bean> 
     </spring:beans> 
     <jdbc-ee:connector name="Database_Global" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"> 
      <!-- <jdbc-ee:query key="RetriveQuery" value="Select * from getData where ID=?"/> --> 
      <jdbc-ee:query key="RetriveQuery" value="CALL sp_myStoredProcedure(?) "/> 
      </jdbc-ee:connector> 

    <flow name="MuleDbInsertFlow1" doc:name="MuleDbInsertFlow1"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/> 
    <cxf:jaxws-service service="MainData" serviceClass="com.test.MainData" doc:name="SOAPWithHeader" /> 
    <component class="com.test.MainDataImpl" doc:name="JavaMain_ServiceImpl"/> 
</flow> 

現在由於我使用存儲過程sp_myStoredProcedure我得到異常(?): -

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [CALL sp_myStoredProcedure(?) ]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'. 
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) 
    at com.vertu.services.schema.maindata.v1.Dao.MainDataDAOImpl.retrieveFromDBMethod(MainDataDAOImpl.java:102) 
    at com.vertu.services.schema.maindata.v1.Impl.MainDataImpl.retrieveDataOperation(MainDataImpl.java:73) 

但是,如果使用普通的SQL查詢: - Select * from getData where ID=?它工作正常,沒有任何問題......在我的DAOImpl課程是我們的荷蘭國際集團下面的代碼: -

String retrieveDataFromDB = getQueryByKey("RetriveQuery"); 

jdbcTemplate.query(retrieveDataFromDB, new Object[] { ID }, 
        new RowMapper() { 

         @Override 
         public Object mapRow(ResultSet rs, int line) 
           throws SQLException { 
          System.out.println("inside row mapper"); 
          // Display records 
          dataResponse.setId(rs.getInt("ID")); 
          dataResponse.setName(rs.getString("NAME")); 
          dataResponse.setAge(rs.getInt("AGE")); 
          dataResponse.setDesignation(rs 
            .getString("DESIGNATION")); 
          dataResponse 
            .setResponse("The Data retrieved from the Database"); 
          return 1; 
} 
}); 

請幫助...什麼是存儲過程的問題,即是正常的SQL查詢工作正常參數???

+0

請停止碰撞你的問題,否則我們將被迫將其鎖定,這將阻止它完全得到答案。 – BoltClock

+0

什麼問題? –

+0

問題是,反覆碰撞您的問題是具有破壞性和不考慮的。 – BoltClock

回答

0

請查閱最新版本的mule 3.6存儲過程調用用法。

<db:stored-procedure config-ref="Oracle_Configuration1" doc:name="Database"> 
 
      <db:parameterized-query><![CDATA[{call apps.create_sales_Order(:p_header_rec_oper,:P_order_number,:P_ordered_date,:P_line_id,:p_flow_Status_code,:P_return_status)}]]></db:parameterized-query> 
 
      <db:in-param name="p_header_rec_oper" value="CREATE"/> 
 
      <db:out-param name="P_order_number" type="INTEGER"/> 
 
      <db:out-param name="P_ordered_date" type="DATE"/> 
 
      <db:out-param name="P_line_id" type="VARCHAR"/> 
 
      <db:out-param name="p_flow_Status_code" type="VARCHAR"/> 
 
      <db:out-param name="P_return_status" type="VARCHAR"/> 
 
      
 
</db:stored-procedure> 
 

 
{ 
 
• \t P_return_status: "S", 
 
• \t P_line_id: "684229", 
 
• \t p_flow_Status_code: "ENTERED", 
 
• \t P_ordered_date: "2015-05-22", 
 
• \t P_order_number: 69393 
 
}

+0

謝謝..但是,這已經完成,是非常舊的線程,我實際上是用舊的JDBC組件 –