【问题标题】:Storing data from select statement created by stored procedure存储由存储过程创建的 select 语句中的数据
【发布时间】:2016-09-27 20:41:01
【问题描述】:

我希望标题有意义。

假设我有一个存储过程(在 Microsoft SQL Server 中),它根据一些参数生成一个 select 语句,然后在表上执行该 select 语句。假设表是Users,select 语句返回表中的第一个用户。用户拥有IDfnamelname

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

在eclipse中,我想使用Spring和JdbcTemplate,我正在考虑使用可调用语句。有什么想法吗?

【问题讨论】:

    标签: java sql-server spring stored-procedures


    【解决方案1】:

    来自 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      • 2019-01-14
      • 1970-01-01
      相关资源
      最近更新 更多