简体   繁体   中英

Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate

Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate. My Stored Procedure last parameter is a input/out parameter if the record is updated I will get back "Y" from the main frame. Can someone please give me a close on how to access the 2nd parameter and see if it is a "Y"

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("as400.xml"));
DataSource ds = (DataSource) beanFactory.getBean("dataSource");
jdbc = new JdbcTemplate(ds);
int res= jdbc.update("{CALL TESTONE(?,?)}", new Object[] { new String("JOHN"), new String("N") });

To get back the values from a stored procedure, you need to create your own class that extends StoredProcedure , declare your parameters, and then examine the out parameters that are returned from the execute call:

public final class MyProc extends StoredProcedure {

    public MyProc() {
        super(myDataSource, "TESTONE");
        declareParameter(new SqlParameter("param1", Types.CHAR));
        declareParameter(new SqlOutParameter("param2", Types.CHAR));
    }

    public String execute(Map<?, ?> inParams) {
        Map results = super.execute(inParams);
        return (String) results.get("param2");
    }
}

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