public static void main(String[] args) {
String jhlsh = null;
String jhlsh2 = null;
int id = 0;
int num;
try {
Connection con = Util.getConnection();
Statement stmt = con.createStatement();
ResultSet res = stmt
.executeQuery("select jhlsh from test_id where yljg= '00000001'");
while (res.next()) {
jhlsh = res.getString("jhlsh");
}
id = Integer.parseInt(jhlsh) + 1;
jhlsh2 = id + "";
switch (jhlsh2.length()) {
case 1:
jhlsh2 = "000" + jhlsh2;
break;
case 2:
jhlsh2 = "00" + jhlsh2;
break;
case 3:
jhlsh2 = "0" + jhlsh2;
break;
case 4:
jhlsh2 = jhlsh2;
break;
}
int i = stmt.executeUpdate("update test_id set jhlsh ='" + jhlsh2
+ "' where yljg = '00000001'");
res.close();
stmt.close();
con.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
SimpleDateFormat smp = new SimpleDateFormat("yyyyMMdd");
Date d = calendar.getTime();
try {
Runtime.getRuntime().exec(
"exp zjhit/zjhit@DRG file=d://daochu00000001" + jhlsh2
+ smp.format(d) + ".dmp tables=(ACE_MEDLIST)");
} catch (IOException e1) {
e1.printStackTrace();
}
File f = new File("d:/daochu00000001" + jhlsh2 + smp.format(d) + ".dmp");
while (!f.exists()) {
System.out.println("无文件");
}
String rarPath = "C:\\Program Files\\WinRAR\\WinRAR.exe";
String cmd = "";
String zipfile;
String foler;
zipfile = "d:/daochu00000001" + jhlsh2 + smp.format(d) + ".zip";
foler = "d:/daochu00000001" + jhlsh2 + smp.format(d) + ".dmp";
cmd = rarPath + " m -hp123456 " + zipfile + "  " + foler;
System.out.println(cmd);
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }我现在运行这段代码的时,出现一个错误。
!   d:\daochu00000001007120091111.zip: 无法打开 daochu00000001007120091111.dmp
!   另一个程序正在使用此文件,进程无法访问。
是怎么回事啊? 
高手帮忙解决一下……

解决方案 »

  1.   

    !  另一个程序正在使用此文件,进程无法访问。 daochu00000001007120091111.dmp 多处使用,一个线程还没有处理完,另外一个线程同时请求了该资源,导致资源冲突。仔细检查下程序。
      

  2.   

    你的eclipse的控制台窗口上,有一个小显示器的图标,旁边有个向下的小三角形。
    点那个,看看你这个PG是不是启动过几次了。
    估计你是启动多次了,上一次还没关,这次有启动了。
      

  3.   

    1.Runtime.getRuntime().exec(
                        "exp zjhit/zjhit@DRG file=d://daochu00000001" + jhlsh2
                                + smp.format(d) + ".dmp tables=(ACE_MEDLIST)");
    ; 2.File f = new File("d:/daochu00000001" + jhlsh2 + smp.format(d) + ".dmp");
    3.Runtime.getRuntime().exec(cmd);
    都在使用dmp文件,1文件使用完后没有关闭,所以造成2,3使用的时候冲突