Spring JDBC 调用 procedure

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

import com.qeweb.redants.dao.ISequenceDao;

public class SequenceDaoImpl extends SimpleJdbcDaoSupport implements
        ISequenceDao {
    Log log = org.apache.commons.logging.LogFactory
            .getLog(SequenceDaoImpl.class);

    public String findSequence() {
        String result = (String) getJdbcTemplate().execute(
                new ProcCallableStatementCreator(),
                new ProcCallableStatementCallBack());
        log.info("new material Code:" + result);
        return result;
    }

    class ProcCallableStatementCreator implements CallableStatementCreator {
        public CallableStatement createCallableStatement(Connection connection)
                throws SQLException {
            String proc_name = "{call proc_sequence(?)}";
            CallableStatement callableStatement = connection
                    .prepareCall(proc_name);
            callableStatement.registerOutParameter(1, java.sql.Types.VARCHAR);
            return callableStatement;
        }
    }

    class ProcCallableStatementCallBack implements CallableStatementCallback {
        public Object doInCallableStatement(CallableStatement callableStatement)
                throws SQLException, DataAccessException {
            callableStatement.execute();
            String seq = callableStatement.getString(1);
            return seq;
        }
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值