gpt4 book ai didi

java - 在 Java 中调用 Oracle Sproc 时出现问题(使用 Spring 3.0)

转载 作者:行者123 更新时间:2023-11-30 04:38:08 25 4
gpt4 key购买 nike

在使用Spring 3.0的Java开发中,我在执行为 Oracle 编写的存储过程时遇到问题。

这是存储过程代码:

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);

END ADD_PRODUCT;

这是代码(在 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
<小时/>

谁能帮我调试这个。

谢谢。

最佳答案

您正在使用存储过程,因此使用withProcedureName代替withFunctionName,如下所示:

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

withFunctionName 期望返回类型与 DB function 应该具有的类型相同。

关于java - 在 Java 中调用 Oracle Sproc 时出现问题(使用 Spring 3.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12937843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com