gpt4 book ai didi

java - 从 Java 调用 Oracle 函数

转载 作者:太空宇宙 更新时间:2023-11-04 08:25:57 26 4
gpt4 key购买 nike

我有以下功能规范:

FUNCTION FUNC_GET_SOMETHING_FROM_DATABASE ( IN_parameter1           IN VARCHAR2,                                            IN_parameter2           IN VARCHAR2,                                            IN_parameter3           IN VARCHAR2,                                            IN_parameter4           IN VARCHAR2,                                            IN_parameter5           IN VARCHAR2,                                            IN_parameter6           IN VARCHAR2) RETURN REFCURTYP;

Following is my method in Java that is calling the function in Oracle:

public List<SomeVO> getLogReport(            String parameter1, String parameter2, String parameter3,            String parameter4, String parameter5,            String parameter6) throws BlahException, RemoteDataAccessException {        Vector<Object> params = new Vector<Object>();        DataCollectionImpl<LogReportVO> someData = new DataCollectionImpl<LogReportVO>(                LogReportVO.class);                // IN Parameters        params.add(parameter1);        params.add(parameter2);        params.add(parameter3);        params.add(parameter4);        params.add(parameter5);        params.add(parameter6);        //Out Parameter        params.add(new DBParameter(DBParameter.OUT, DBParameter.CURSOR));        try {            callStoredProcedure(                    Constants.FUNC_GET_SOMETHING_FROM_DATABASE, params);        } catch (RemoteDataAccessException e) {            throw new BlahException("LogReportDAO",                    "getLogReport", e.getMessage(),                    e.getRealException());        }        return someData.getDataCollectionObjects();    }

The error I am getting is:

wrong number or types of arguments in call

其他信息:

protected void callStoredProcedure(String procedureName, Vector params) throws RemoteDataAccessException {        callStoredProcedure(getSchema(), procedureName, params);    }    protected void callStoredProcedure(String schema, String procedureName, Vector params) throws RemoteDataAccessException {        callStoredProcedure(getDatasource(), schema, procedureName, params);    }    protected void callStoredProcedure(String dataSourceName, String schema, String procedureName, Vector params) throws RemoteDataAccessException {        getOracleConnection(dataSourceName).callStoredProcedure(                getFullyQualifiedProcedureName(schema, procedureName), params);    }    private OracleConnection getOracleConnection(String datasource) {           OracleConnection oraConn = null;        try {               oraConn = new OracleConnection(datasource);         } catch (RemoteDataAccessException rdae) {              log.fatal("BaseDAO.getOracleConnection " + rdae.getMessage(), rdae);        } catch (Exception ie) {                log.fatal("BaseDAO.getOracleConnection" + ie.getMessage(), ie);        }        return oraConn;    }

最佳答案

您的代码很可能没有考虑存储过程的返回值。

为什么不使用标准 JDBC 方式来调用存储过程?它就像一个魅力。

http://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/callablestatement.html

关于java - 从 Java 调用 Oracle 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8539402/

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