能给个JSP备份MS SQL的例子吗?给了马上给分~!

52800195 2004-09-04 03:37:40
如题目~!要的是WEB形式的~!急用~!
谢谢~!刚学JSP,做一个课程设计~!
...全文
250 点赞 收藏 18
写回复
18 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
makay 2004-09-07
mark
回复
panzi667 2004-09-07
vampirewp() ( ) 信誉:100 的方法能实现么?
回复
xqi8 2004-09-07
up
回复
vampirewp 2004-09-07
根据楼上aiwngye(graceping) 备份数据库的方法,写了个还原的方法
public boolean restoreDb(String dbName, String path) throws Exception {
boolean flag = false;

Connection conn = ...;//得到连接
if (conn == null) {
//
}
Statement stmt = null;
String sql = null;
try {
File test = new File("d:\\dbBack");
if (!test.isDirectory()) {
//异常处理
}
File srcfile = new File(path);
File descfile = new File(dbRestorePath);
String preCmd = "";
if (!srcfile.isFile()) {
//异常处理
}
if (descfile.isFile() ) {
preCmd = "echo A|";
} else {
preCmd = "echo F|";
}
String cmd = preCmd + " xcopy " + path + " " + dbRestorePath + " /e";

FileWriter fw = new FileWriter(new File(cmdDbFile));
fw.write(cmd);
fw.close();
callCmd(cmdDbFile);
Thread.sleep(30*1000);
sql = "Exec sp_dboption '" + dbName + "','single user','True' " +
" RESTORE DATABASE [" + dbName+"] " +
" FROM disk=N'" + dbRestorePath + "' "+
" with file=1, RECOVERY,replace ";

stmt = conn.createStatement();
stmt.executeUpdate(sql);
flag = true;
} catch (Exception ex) {
//异常处理
} finally {
//释放资源
}
return flag;
}
回复
hary90 2004-09-07
up
回复
power17 2004-09-07
请教楼上的。要是想还原又用什么语句。
回复
guyizh 2004-09-07
把这个放到数据语句集里有可以的了:

BACKUP DATABASE ge_0001 TO DISK = 'd:\backup.dat'
回复
xqi8 2004-09-06
up
回复
52800195 2004-09-06
操作备份~!就像ASP的OA那里有数据备份的~!

谢谢楼上二位~!
楼上的~!你那用到什么类~!能帮我写放在WEB中可以运行的吗?
写一个javabean也行~!谢谢二位~!
回复
aiwngye 2004-09-06
用下面的方法可以实现(供参考)
private void callCmd(String pathfile) throws Exception {
String[] cmd=new String[3];
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "start /MIN " + pathfile;
Process pro = Runtime.getRuntime().exec(cmd);
}

public boolean backDb(String dbName, String path) throws Exception {
boolean flag = false;
Connection conn = ...; //获取数据库连接
Statement stmt = null;
String sql = null;
try {
File test = new File("d:\\dbBack");
if (!test.isDirectory()) {
//抛出异常
}
sql = "BACKUP DATABASE [" + dbName + "] TO " +
"DISK = N'" + dbBackPath + "' " +
"WITH INIT , NOUNLOAD , " +
"NAME = N'" + dbName + " backup', SKIP , STATS = 10, NOFORMAT";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
File srcfile = new File(dbBackPath);
if (!srcfile.isFile()) {
//抛出异常
}
File descfile = new File(path);
String preCmd = "";
if (!descfile.isFile()) {
preCmd = "echo F|";
} else {
preCmd = "echo A|";
}
String cmd = preCmd + " xcopy " + dbBackPath + " " + path + " /e";
logger.debug(" backDb() : copy file cmd : " + cmd);
FileWriter fw = new FileWriter(new File(cmdDbFile));
fw.write(cmd);
fw.close();
callCmd(cmdDbFile);
flag = true;
} catch (Exception ex) {
throw ex;
} finally {
//关闭连接
}
return flag;
}
回复
AHUA1001 2004-09-06
你的意思是作定时备份还是操作备份啊?
如果是定时备份,那就不需要用java了,MS SQL自带这种功能。
如果是操作备份,那就需要有这个权限,而且是很高的权限,那就不如直接用MS SQL的工具呢。
要不你用JAVA把数据库的内容读出来,写入一个文件,文本文件就可以,然后在用代码读回去,这样就太麻烦了。
回复
keespeed 2004-09-06
关注!!!!!!
回复
52800195 2004-09-06
顶一下~!
回复
minghuitian 2004-09-06
gz
回复
mickeylm 2004-09-06
帮你顶
回复
52800195 2004-09-06
up
回复
CHLC 2004-09-06
up
回复
52800195 2004-09-06
UP一下~!
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-04 03:37
社区公告
暂无公告