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("調用結束");

   }

}
相關文章
相關標籤/搜索