How to use spring simplejdbctemplate to call stored procedures
jrequioma Nov 25, 2010 8:34 PMHi, I am new to SEAM and i got a requirement to execute an oracle sproc from a seam-gen'ed Form which i replaced the code from one of the discussions to try out for myself. But there are some error messages displayed in my eclipse IDE saying:
The method execute(ConnectionCallback) is undefined for the type SimpleJdbcTemplate for this line:
BigDecimal result = (BigDecimal) template.execute(connectionCallBack);
What am i missing here? So far i don't see a consolidated listing of the sample code. So i just tried to patch up here and there (remove throws exception, etc.) as per advice. Did i patch correctly? Below is my action class:
package com.mydomain.testapp.action;
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import java.math.BigDecimal;
import org.hibernate.sql.Template;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
@Name("testspcall")
public class Testspcall implements Serializable
{
@In("#{jdbcTemplate}")
private transient static SimpleJdbcTemplate template;
@SuppressWarnings("unchecked")
public static BigDecimal calcDistance(final String zipcode, final BigDecimal lat, final BigDecimal lon)
{
ConnectionCallback connectionCallBack = new ConnectionCallback() {
@Override
public Object doInConnection(Connection conexion_db)
{
BigDecimal result;
CallableStatement statement = conexion_db.prepareCall("{call CalcDistance(?, ?, ?, ?)}");
statement.setString(1, zipcode);
statement.setBigDecimal(2, lat);
statement.setBigDecimal(3, lon);
statement.registerOutParameter(4, Types.DOUBLE);
statement.execute();
result = statement.getBigDecimal(4);
return result;
}
};
BigDecimal result = (BigDecimal) template.execute(connectionCallBack);
return result;
}