1

在使用 Spring 3.0 进行 Java 开发时,我在执行为 Oracle 编写的 Sproc 时遇到问题。

这是 Sproc 代码:

create or replace PROCEDURE            
ADD_PRODUCT
( product_id IN VARCHAR2
, description IN VARCHAR2
, weight IN FLOAT
, specification IN VARCHAR2
, category IN VARCHAR2
, manufacturer IN VARCHAR2
, syncount IN NUMBER
, nonAccentedURL IN VARCHAR2
, nonAccentedManufacturer IN VARCHAR2
) AS
    recCount number;
BEGIN
      recCount := 0;

      SELECT    COUNT(*) 
      INTO  recCount
      FROM  ERP_MANUFACTURER
      WHERE NAME = manufacturer;  



  IF recCount < 1 THEN
    INSERT INTO ERP_MANUFACTURER (NAME, URL) VALUES (manufacturer,     nonAccentedManufacturer);
  END IF;

  INSERT INTO ERP_PRODUCT (ID, DESCRIPTION, WEIGHT, SPECIFICATION, CATEGORY, MANUFACTURER, SYNCCOUNT, URL) 
  VALUES     (product_id,description,weight,specification,category,manufacturer,syncount,nonAccentedURL);        

结束添加_产品;

这是代码(在 DAO 中):

public int ADD_Product(String codigo_produto, String descricao, float peso, String espeficiacao, String categoria, String fabricante, int sysCount, int SENT_STATUS) throws Exception {

    SimpleJdbcCall caller = new SimpleJdbcCall(this.jdbcTemplate).withFunctionName("ADD_PRODUCT");

    MapSqlParameterSource paramMap = new MapSqlParameterSource();

    paramMap.addValue("product_id", codigo_produto, Types.VARCHAR);
    paramMap.addValue("description", descricao, Types.VARCHAR);
    paramMap.addValue("weight", peso, Types.FLOAT);
    paramMap.addValue("specification",espeficiacao, Types.VARCHAR);
    paramMap.addValue("category", categoria, Types.VARCHAR);
    paramMap.addValue("manufacturer", fabricante, Types.VARCHAR);
    paramMap.addValue("syncount", sysCount, Types.NUMERIC);
    paramMap.addValue("nonAccentedURL", URLEncoder.encode(deAccent(espeficiacao).toLowerCase(), "UTF-8"), Types.VARCHAR);
    paramMap.addValue("nonAccentedManufacturer", URLEncoder.encode(deAccent(fabricante).toLowerCase(), "UTF-8"), Types.VARCHAR);

    Map<String, Object> i = caller.execute(paramMap);

    return i.size();
}

执行此方法时,错误日志如下:


org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{? = call ADD_LOG(?, ?, ?, ?)}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 13:

PLS-00306:调用“ADD_LOG”时参数的数量或类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略

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:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:391)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:354)
at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:181)
at br.edeploy.voive.dao.ProductDAO.ADD_Log(ProductDAO.java:139)
at br.edeploy.voice.service.ProdutosIn.doGet(ProdutosIn.java:277)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler.couldntFind(DefaultResourceNotFoundHandler.java:41)
at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:71)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:23)
at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92)
at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:56)
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

引起:java.sql.SQLException:ORA-06550:第 1 行,第 13 列:PLS-00306:调用“ADD_LOG”时参数的数量或类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:语句忽略

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:944)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1005)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
... 34 more

谁能帮我调试一下。

谢谢。

4

2 回答 2

2

您正在使用Stored Procedure因此withProcedureName代替withFunctionName如下:

SimpleJdbcCall caller = 
          new SimpleJdbcCall(this.jdbcTemplate).withProcedureName("ADD_PRODUCT");

withFunctionName期望 DBfunction应该具有的返回类型。

于 2012-10-17T15:34:15.937 回答
0

Oracle 中的对象是一个存储过程。您的SimpleJdbcCall对象需要使用withProcedureNamenotwithFunctionName

SimpleJdbcCall caller = new SimpleJdbcCall(this.jdbcTemplate).withProcedureName("ADD_PRODUCT");

在 Oracle 中,函数返回一个值,而过程不返回。语法

{? = call ADD_LOG(?, ?, ?, ?)}

要求它ADD_LOG是一个返回值的函数。您发布的日志似乎是针对具有不同数量参数的不同存储过程调用(ADD_LOG而不是)。ADD_PRODUCT

于 2012-10-17T15:34:23.263 回答