scorchio96
Aug 25th, 2004, 12:35 AM
I'm trying to get the results of a JdbcTemplate call on a stored procedure. I can't figure out from the documentation how to extract the results.
Can anyone provide me with an example of how this should be used?
Thanks,
Kim
MS SQL Stored proc:
CREATE PROCEDURE
SP_GET_NEXT_SEQU (@MYTABLE char(25))
AS
BEGIN TRANSACTION
BEGIN
UPDATE F_SEQU WITH (UPDLOCK) Set SQ_COUNT=SQ_COUNT+1 WHERE SQ_TABLE=@MYTABLE
SELECT SQ_COUNT FROM F_SEQU WHERE SQ_TABLE=@MYTABLE
END
COMMIT TRANSACTION
GO
And the method in my DAO that extends JdbcDaoSupport:
public int getNextSequ(final String tableName) {
int sequ = 0;
final List sequs = new ArrayList();
RowCallbackHandler rch = new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
sequs.add(new Integer(rs.getInt(1)));
}
};
List params = new ArrayList();
SqlReturnResultSet rsr = new SqlReturnResultSet("sequ", rch);
params.add(rsr);
Map results = getJdbcTemplate().call(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con) throws SQLException {
CallableStatement cs = con.prepareCall("{call SP_GET_NEXT_SEQU (?)}");
cs.setString(1, tableName);
return cs;
}
}, params);
if (!sequs.isEmpty())
sequ = ((Integer)sequs.iterator().next()).intValue();
return sequ;
}
Can anyone provide me with an example of how this should be used?
Thanks,
Kim
MS SQL Stored proc:
CREATE PROCEDURE
SP_GET_NEXT_SEQU (@MYTABLE char(25))
AS
BEGIN TRANSACTION
BEGIN
UPDATE F_SEQU WITH (UPDLOCK) Set SQ_COUNT=SQ_COUNT+1 WHERE SQ_TABLE=@MYTABLE
SELECT SQ_COUNT FROM F_SEQU WHERE SQ_TABLE=@MYTABLE
END
COMMIT TRANSACTION
GO
And the method in my DAO that extends JdbcDaoSupport:
public int getNextSequ(final String tableName) {
int sequ = 0;
final List sequs = new ArrayList();
RowCallbackHandler rch = new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
sequs.add(new Integer(rs.getInt(1)));
}
};
List params = new ArrayList();
SqlReturnResultSet rsr = new SqlReturnResultSet("sequ", rch);
params.add(rsr);
Map results = getJdbcTemplate().call(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con) throws SQLException {
CallableStatement cs = con.prepareCall("{call SP_GET_NEXT_SEQU (?)}");
cs.setString(1, tableName);
return cs;
}
}, params);
if (!sequs.isEmpty())
sequ = ((Integer)sequs.iterator().next()).intValue();
return sequ;
}