[转载]SQL Server 2000数据库的备份与恢复
文章出处:
http://blog.sina.com.cn/s/blog_4a5ca0240100091n.html
备份代码
Connection con = 得到数据库连接();
String fileName = “C:/backup.bak”; String sql = "backup database 数据库名 to disk = ?";
PreparedStatement pm = con.prepareStatement(sql); pm.setString(1, fileName); pm.execute();
JOptionPane.showMessageDialog(null, "数据库备份成功"); |
恢复代码
Connection con = 得到数据库连接(); //此时数据库必须连接到master库
String fileName = “C:/backup.bak”; String sql = " restore database 数据库名 from disk=?";
PreparedStatement pm = con.prepareStatement(sql); pm.setString(1, fileName); pm.execute();
JOptionPane.showMessageDialog(null, "数据库恢复成功"); |