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;
}
}
}
Spring JDBC 调用 procedure
最新推荐文章于 2022-04-27 10:10:21 发布