import java.sql.Types;
import java.util.Collections;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.object.StoredProcedure;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("context.xml", Main.class);
DataSource dataSource = (DataSource) ac.getBean("dataSource");
//DataSource mysqlDataSource = (DataSource) ac.getBean("mysqlDataSource");
MeaningOfLife meaningOfLife = new MeaningOfLife(dataSource);
Map result = meaningOfLife.execute(Collections.emptyMap());
System.out.println(result.values().iterator().next());
}
}
class MeaningOfLife extends StoredProcedure {
private static final String SQL = "f_calculate";
MeaningOfLife(DataSource dataSource) {
super(dataSource, SQL);
setFunction(true);
declareParameter(new SqlOutParameter("n", Types.INTEGER));
}
int executeAndGet() {
return (Integer)execute(Collections.emptyMap()).values().iterator().next();
}
}
|