简体   繁体   中英

How to retrieve the data from stored procedure using spring NamedParameterJdbcTemplate?

I am trying to retrieve the data from a oracle stored procedure using NamedParameterJdbcTemplate and below is the code snippet I am using for the same.

    ApplicationContext context = new ClassPathXmlApplicationContext("/bean.xml");
    DAOImpl dAOImpl = (DAOImpl) context.getBean("daoImpl");

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("param", "value1");

    String query = "{ <SCHEMA_NAME>.<package_name>.<stored_proc>(:param) }"; 

    List<String[]> arrList = dAOImpl.getDaoTmplt().execute(query, paramMap,new PreparedStatementCallback<List<String[]>>(){

        @Override
        public List<String[]> doInPreparedStatement(PreparedStatement ps)
                throws SQLException, DataAccessException {

            ResultSet rs = ps.executeQuery();
            List<String[]> arrList = new ArrayList<String[]>();

            while (rs.next()) {

                String[] strArr = new String[4];
                strArr[0] = rs.getString("COLUMN_A");
                strArr[1] = rs.getString("COLUMN_B");
                strArr[2] = rs.getString("COLUMN_C");
                strArr[3] = rs.getString("COLUMN_D");

                arrList.add(strArr);     
            }
            rs.close();
            return arrList;
        }
    });

and I am getting below mentioned exception :

PreparedStatementCallback; bad SQL grammar [{ CALL <SCHEMA_NAME>.<package_name>.<stored_proc>(?) }]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00221: '<stored_proc>' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

When I run the below query in TOAD it returns the data -

select <SCHEMA_NAME>.<package_name>.<stored_proc>('value1') from dual;

Can someone please correct me if I am going wrong somewhere?

Thanks in advance!

Try calling your SP with execute not with executeQuery

ps.execute();
ResultSet rs = ps.getResultSet();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM