java调用存储过程

package com.tepusoft.modules.synchr.task;
      import java.sql.CallableStatement;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.SQLException;
      import java.text.MessageFormat;
      import java.util.List;
      import javax.sql.DataSource;
      import com.tepusoft.common.config.Global;
      import org.junit.Before;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.context.annotation.Lazy;
      import org.springframework.scheduling.annotation.Scheduled;
      import org.springframework.stereotype.Service;
      import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
      import org.springframework.test.context.web.WebAppConfiguration;
      import com.alibaba.druid.util.OracleUtils;

/**
 * Created by ltx on 2017/9/6.
 */
@Service
@Lazy(false)
public class SynchroTask {

   @Autowired
   DataSource dataSource;
   Connection conn;
   CallableStatement st;


   @Scheduled(cron="*/5 * * * * ?") //间隔2分执行 ,定时器  

   public void taskCycle(){

      try {

         //加载驱动
         DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
         //得到链接
         Connection conn=DriverManager.getConnection(Global.getConfig("jdbc.url"),Global.getConfig("jdbc.username"),Global.getConfig("jdbc.password"));
         CallableStatement c=conn.prepareCall("{call fn_merge_office()}");  //写存储过程的名字
         c.execute();
         conn.close();
      } catch (SQLException e) {
         e.printStackTrace();
      }
      System.out.println("调用结束");

   }

}
相关文章
相关标签/搜索