try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:ClothingSale","sa","");
Statement s = c.createStatement();
c.close();
s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");
s.execute("RESTORE DATABASE ClothingSale FROM DISK = 'D:\\ClothingSale.bak'"
+"WITH MOVE 'ClothingSale' TO 'D:\\ClothingSale_Data.mdf',MOVE 'ClothingSale_log' TO 'D:\\ClothingSale.ldf'");
JOptionPane.showMessageDialog(null,"恢复成功");
s.close();
}
catch(Exception ex){
System.out.println(ex.getMessage());
}为什么出现Invalid handle错误? SQL语句应该怎样写??
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:ClothingSale","sa","");
Statement s = c.createStatement();
c.close();
s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");
s.execute("RESTORE DATABASE ClothingSale FROM DISK = 'D:\\ClothingSale.bak'"
+"WITH MOVE 'ClothingSale' TO 'D:\\ClothingSale_Data.mdf',MOVE 'ClothingSale_log' TO 'D:\\ClothingSale.ldf'");
JOptionPane.showMessageDialog(null,"恢复成功");
s.close();
}
catch(Exception ex){
System.out.println(ex.getMessage());
}为什么出现Invalid handle错误? SQL语句应该怎样写??
放在
s.close();
后面。
如果还不行,说明你的
s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");
里面的语句是command命令,不能使用类似sql一样的语句来执行,应该用Runtime的exec来执行
把s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");这句去掉了也不行