Spring Java

File: context.xml

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                           http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

    
    
    
    
    
    

    
        
    
    
    
        
    

File: Main.java
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.SqlParameter;
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");
    ActStartled  actStartled = new ActStartled(dataSource);
    
    actStartled.execute(1);
  }
}
class ActStartled extends StoredProcedure {
  private static final String SQL = "p_proc";
  ActStartled(DataSource dataSource) {
      super(dataSource, SQL);
      declareParameter(new SqlParameter("n", Types.INTEGER));
  }
  void execute(int value) {
      Map parameters = new HashMap(1);
      parameters.put("n", value);
      execute(parameters);
  }
}
           
       
Spring-StoredProcedureWithParameter.zip( 3,655 k)