我有个简单程序要实现这样一个功能:我通过程序来执行一个存储过程(执行时间约1个小时),存储过程执行结束会在某个目录下面生成几个文件,然后我通过程序把这几个文件得到,然后接着执行下面的代码。
  现在遇到的问题是:当我在数据库客户端工具(如PL/SQL)上执行该存储过程的时候,完全可以正确执行,文件也能正确产生,但是当我用程序执行的时候文件还没产生,也就是存储过程还没执行结束就开始执行紧跟着的代码段了,请问我如何使存储过程完全执行?
以下是存储过程执行的方法:
public void doProc(String procname, String url,
                       String user, String password, String driveclass) {
        Connection con = this.getConn(url, user, password, driveclass);
        CallableStatement calls = null;
        String day = fou.getDate(0,"yyyy-MM-dd","d");
        try {
            String sql = "{ call " + procname + "(?)}";
            System.out.println("存储过程:"+sql+"  "+day);
            calls = con.prepareCall(sql);
            calls.setString(1, day);
            System.out.println(sql);
            calls.execute();
        } catch (SQLException ex) {
            System.out.println("执行存储过程出现异常_xsh");
            ex.printStackTrace();
        }finally{
            this.freeDBRes(con, calls);
        }
    }
以下是调用存储过程的上下文:
              System.out.println("start:" + d1);
              ju.doProc(ArgumentInit.procname,
                                 ArgumentInit.dburl, ArgumentInit.dbuser,
                                 ArgumentInit.dbpassword, ArgumentInit.driveclass);
                  Date date2 = new Date();
                  String d2 = sdf.format(date2);
                  System.out.println("end :"+d2);
以下是在数据库客户端存储过程的执行方式:P_CLUBBER_JF_FB_WXF '2009-10-10';
调用存储过程执行方法时使用的存储过程名为:ArgumentInit.procname="P_CLUBBER_JF_FB_WXF"
如果大家什么地方觉得我说的不清楚,麻烦你留言说一下,多谢了!

解决方案 »

  1.   

    用JAVA多线程来解决啊 一个线程等待 一个线程唤醒。。
      

  2.   

    那请问如何控制存储过程执行情况啊?存储过程提供返回值?判断文件是否存在?
    还有个地方我要说明一下:假如2点程序开始执行存储过程,直到程序执行结束,然后一直到5点文件都没有产生,那是不是当程序执行到“ Date date2 = new Date(); ”这个地方的时候,存储过程已经停止执行了?