简体   繁体   中英

Storing data from select statement created by stored procedure

I hope the title makes sense.

Let's say I have a stored procedure (in Microsoft SQL Server) which generates a select statement based on some parameters and then executes that select statement on a table. Let's say the table is Users and the select statement returns the first user in the table. The user is has an ID , a fname , and an lname .

How can I store the data that is generated by the select statement?

In eclipse, I want to use Spring and JdbcTemplate, and I'm thinking about using a callable statement. Any ideas?

From the Spring documentation: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html

private class GetSysdateProcedure extends StoredProcedure {

    private static final String SQL = "sysdate";

    public GetSysdateProcedure(DataSource dataSource) {
        setDataSource(dataSource);
        setFunction(true);
        setSql(SQL);
        declareParameter(new SqlOutParameter("date", Types.DATE));
        compile();
    }

    public Date execute() {
        // the 'sysdate' sproc has no input parameters, so an empty Map is supplied...
        Map<String, Object> results = execute(new HashMap<String, Object>());
        Date sysdate = (Date) results.get("date");
        return sysdate;
    }
}

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