请问用JAVA编程语言怎么做SQL2000数据库备份恢复!
1个回答
2011-03-15
展开全部
里备份的是sqlserver数据库:
数据库备份
//备份文件保存路径
String path="D:/sale.bak";
String bakSQL="backup database school to disk=? with init";//SQL语句
java.sql.PreparedStatement bak=DBS.getConnection().prepareStatement(bakSQL);
bak.setString(1,path);//path必须是绝对路径
if(!bak.execute())
over="备份成功";
else
over="备份失败";
bak.close();
数据库还原
if(!DBS.close()){
over="关闭所有链接失败";
}else{
String path="D:/sale.bak";
String reSQL="restore database school from disk=? with replace";
Class.forName(DBInf.getDriverClassName());
java.sql.Connection con=DriverManager.getConnection(DBInf.getMester());
java.sql.PreparedStatement reStmt=con.prepareStatement(reSQL);
reStmt.setString(1,path);//path必须是绝对路径
if(!reStmt.execute())
over="恢复成功";
else
over="恢复失败";
reStmt.close();
con.close();
}
参考资料:
数据库备份
//备份文件保存路径
String path="D:/sale.bak";
String bakSQL="backup database school to disk=? with init";//SQL语句
java.sql.PreparedStatement bak=DBS.getConnection().prepareStatement(bakSQL);
bak.setString(1,path);//path必须是绝对路径
if(!bak.execute())
over="备份成功";
else
over="备份失败";
bak.close();
数据库还原
if(!DBS.close()){
over="关闭所有链接失败";
}else{
String path="D:/sale.bak";
String reSQL="restore database school from disk=? with replace";
Class.forName(DBInf.getDriverClassName());
java.sql.Connection con=DriverManager.getConnection(DBInf.getMester());
java.sql.PreparedStatement reStmt=con.prepareStatement(reSQL);
reStmt.setString(1,path);//path必须是绝对路径
if(!reStmt.execute())
over="恢复成功";
else
over="恢复失败";
reStmt.close();
con.close();
}
参考资料:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询