java语言恢复数据库问题

lzm1988 2009-12-15 11:58:38


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语句应该怎样写??
...全文
114 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzm1988 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 lzm1988 的回复:]
Java codetry{
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语句应该怎样写??
[/Quote]
不能放在后面 放在后面就会出现什么排它访问权的错误~~用RUNTIME怎么写?
lzm122613 2009-12-16
  • 打赏
  • 举报
回复
自己解决了。。。哎
crazylaa 2009-12-16
  • 打赏
  • 举报
回复
c.close();
放在
s.close();
后面。
如果还不行,说明你的
s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");
里面的语句是command命令,不能使用类似sql一样的语句来执行,应该用Runtime的exec来执行
lzm1988 2009-12-16
  • 打赏
  • 举报
回复
我用的是SQL2000 求救各位大侠啊!!!
把s.execute("RESTORE FILELISTONLY FROM DISK = 'D:\\ClothingSale.bak'");这句去掉了也不行
lzm1988 2009-12-16
  • 打赏
  • 举报
回复
能不能具体一点......
crazylaa 2009-12-16
  • 打赏
  • 举报
回复
Runtime调用command命令,网上一大堆

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧