从存储的函数中获取结果

时间:2019-05-06 19:41:43

标签: java hibernate

我要执行存储的功能。它接受参数并产生一个结果。但是我如何得出结果呢? 错误:从内部类引用的局部变量必须是final或有效的final

    public static String season_overlap(int userid, Date sAnf, Date sEnd) throws DatabaseException {
        Session hsession = null;
        String result = null;

        try {
            hsession = HibernateUtil.getSessionFactory().openSession();
            hsession.doWork(new Work() {
                @Override
                public void execute(Connection cnctn) throws SQLException {
                    try (CallableStatement cStmt = cnctn.prepareCall("{? = CALL season_overlap(?, ?, ?)}")) {
                        cStmt.registerOutParameter(1,java.sql.Types.VARCHAR);
                        cStmt.setInt(2, userid);
                        cStmt.setDate(3, sAnf);
                        cStmt.setDate(4, sEnd);
                        cStmt.execute();
                        result = cStmt.getString(1);
                    }
                }
            });
        } catch (HibernateException ex) {
            throw new DatabaseException(ex);
        } finally {
            if (hsession != null)
                hsession.close();
        }

        return result;
    }

0 个答案:

没有答案