plucas
Aug 30th, 2004, 07:26 PM
I found 3 useful articles on the subject:
http://www.springframework.org/docs/reference/jdbc.html#jdbc-StoredProcedure
http://monkeymachine.co.uk/spring/xref-test/org/springframework/jdbc/object/StoredProcedureTestSuite.html
http://forum.springframework.org/viewtopic.php?p=103&highlight=
I have come very close to implementing my own call to a SP... but get the following error:
ResultSet returned from stored procedure but a corresponding SqlReturnResultSet parameter was not declared
here is my code:
package com.pcpower.amss.jdbc;
import java.sql.Types;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.jdbc.core.SqlParameter;
//import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.datasource.*;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
public class SP_PRAZOS_DISPONIVEIS_VENDA {
public static void main(String[] args) {
System.out.println("iniciar o teste de chamar o SP!");
SP_PRAZOS_DISPONIVEIS_VENDA t = new SP_PRAZOS_DISPONIVEIS_VENDA();
t.test();
System.out.println("Done!");
}
void test() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
ds.setUrl("jdbc:jtds:sqlserver://10.100.0.81:1470/NEWCON_PLUS");
ds.setUsername("sa");
ds.setPassword("master");
MyStoredProcedure sproc = new MyStoredProcedure(ds);
Map res = sproc.execute();
printMap(res);
}
private class MyStoredProcedure extends StoredProcedure {
public static final String SQL = "PRAZOS_DISPONIVEIS_VENDA";
private int count = 0;
public MyStoredProcedure(DataSource ds) {
setDataSource(ds);
//setFunction(true);
setSql(SQL);
declareParameter(new SqlParameter("Codigo_Tipo_Grupo", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Bem", Types.INTEGER));
declareParameter(new SqlParameter("Data_Nascimento", Types.DATE));
declareParameter(new SqlParameter("Listar_Apenas_Grupo_Exclusivo", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Representante", Types.VARCHAR));
declareParameter(new SqlParameter("Situacao_Grupo", Types.CHAR));
declareParameter(new SqlParameter("Pessoa", Types.CHAR));
declareParameter(new SqlParameter("Ordem_Pesquisa", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Filail_Comercial", Types.VARCHAR));
declareParameter(new SqlParameter("Rateia", Types.CHAR));
declareParameter(new SqlReturnResultSet("rs", new RowCallbackHandlerImpl()));
compile();
}
public int getCount() {
return count;
}
private class RowCallbackHandlerImpl implements RowCallbackHandler {
public void processRow(ResultSet rs) throws SQLException {
count++;
}
}
public Map execute() {
Map in = new HashMap();
in.put("Codigo_Tipo_Grupo", "IM");
in.put("Codigo_Bem", new Integer(1));
in.put("Data_Nascimento", new Date("01/01/1980"));
in.put("Listar_Apenas_Grupo_Exclusivo", "N");
in.put("Codigo_Representante", "0002");
in.put("Situacao_Grupo", "X");
in.put("Pessoa", "F");
in.put("Ordem_Pesquisa", "G");
in.put("Codigo_Filail_Comercial", "001");
in.put("Rateia", "S");
Map out = execute(in);
return out;
}
}
private static void printMap(Map r) {
Iterator i = r.entrySet().iterator();
while (i.hasNext()) {
System.out.println((String) i.next().toString());
}
}
}
I can't find out how to get a SqlReturnResultSet assigned to this SP. Any help/hints would be greatly appreciated!
TIA,
~plucas
http://www.springframework.org/docs/reference/jdbc.html#jdbc-StoredProcedure
http://monkeymachine.co.uk/spring/xref-test/org/springframework/jdbc/object/StoredProcedureTestSuite.html
http://forum.springframework.org/viewtopic.php?p=103&highlight=
I have come very close to implementing my own call to a SP... but get the following error:
ResultSet returned from stored procedure but a corresponding SqlReturnResultSet parameter was not declared
here is my code:
package com.pcpower.amss.jdbc;
import java.sql.Types;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.jdbc.core.SqlParameter;
//import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.datasource.*;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
public class SP_PRAZOS_DISPONIVEIS_VENDA {
public static void main(String[] args) {
System.out.println("iniciar o teste de chamar o SP!");
SP_PRAZOS_DISPONIVEIS_VENDA t = new SP_PRAZOS_DISPONIVEIS_VENDA();
t.test();
System.out.println("Done!");
}
void test() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
ds.setUrl("jdbc:jtds:sqlserver://10.100.0.81:1470/NEWCON_PLUS");
ds.setUsername("sa");
ds.setPassword("master");
MyStoredProcedure sproc = new MyStoredProcedure(ds);
Map res = sproc.execute();
printMap(res);
}
private class MyStoredProcedure extends StoredProcedure {
public static final String SQL = "PRAZOS_DISPONIVEIS_VENDA";
private int count = 0;
public MyStoredProcedure(DataSource ds) {
setDataSource(ds);
//setFunction(true);
setSql(SQL);
declareParameter(new SqlParameter("Codigo_Tipo_Grupo", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Bem", Types.INTEGER));
declareParameter(new SqlParameter("Data_Nascimento", Types.DATE));
declareParameter(new SqlParameter("Listar_Apenas_Grupo_Exclusivo", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Representante", Types.VARCHAR));
declareParameter(new SqlParameter("Situacao_Grupo", Types.CHAR));
declareParameter(new SqlParameter("Pessoa", Types.CHAR));
declareParameter(new SqlParameter("Ordem_Pesquisa", Types.CHAR));
declareParameter(new SqlParameter("Codigo_Filail_Comercial", Types.VARCHAR));
declareParameter(new SqlParameter("Rateia", Types.CHAR));
declareParameter(new SqlReturnResultSet("rs", new RowCallbackHandlerImpl()));
compile();
}
public int getCount() {
return count;
}
private class RowCallbackHandlerImpl implements RowCallbackHandler {
public void processRow(ResultSet rs) throws SQLException {
count++;
}
}
public Map execute() {
Map in = new HashMap();
in.put("Codigo_Tipo_Grupo", "IM");
in.put("Codigo_Bem", new Integer(1));
in.put("Data_Nascimento", new Date("01/01/1980"));
in.put("Listar_Apenas_Grupo_Exclusivo", "N");
in.put("Codigo_Representante", "0002");
in.put("Situacao_Grupo", "X");
in.put("Pessoa", "F");
in.put("Ordem_Pesquisa", "G");
in.put("Codigo_Filail_Comercial", "001");
in.put("Rateia", "S");
Map out = execute(in);
return out;
}
}
private static void printMap(Map r) {
Iterator i = r.entrySet().iterator();
while (i.hasNext()) {
System.out.println((String) i.next().toString());
}
}
}
I can't find out how to get a SqlReturnResultSet assigned to this SP. Any help/hints would be greatly appreciated!
TIA,
~plucas