2016-09-27 109 views
0

我希望标题有意义。从存储过程创建的select语句中存储数据

假设我有一个存储过程(在Microsoft SQL Server中),它根据某些参数生成select语句,然后在表上执行select语句。假设表格为Users,并且select语句返回表中的第一个用户。用户有一个ID,一个fname和一个lname

如何存储select语句生成的数据?

在eclipse中,我想使用Spring和JdbcTemplate,并且正在考虑使用可调用语句。有任何想法吗?

回答

0

从Spring文档: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; 
    } 
}