📄 db_restore.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312" errorPage="error.jsp"%>
<jsp:directive.page import="java.sql.Connection"/>
<jsp:directive.page import="java.sql.DriverManager"/>
<jsp:directive.page import="java.sql.Statement"/>
<jsp:directive.page import="java.sql.ResultSet"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'db_restore.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="../css/sys.css">
<style type="text/css">
<!--
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
background-color: #FFFFFF;
}
a:link {
color: #1A438E;
text-decoration: underline;
}
a:visited {
text-decoration: underline;
}
a:hover {
text-decoration: none;
color: #000000;
}
a:active {
text-decoration: underline;
}
-->
</style>
<script language="javascript" language="javascript">
function check(){
var physical = document.getElementById("path").value;
var length = physical.length;
var charindex = physical.lastIndexOf("\\");
var extent = physical.substring(charindex + 1,physical.length).toLowerCase();
var length2 = extent.length;
var charindex2 = extent.lastIndexOf(".");
var extent2 = extent.substring(charindex2,extent.length).toLowerCase();
if(form1.path.value == ""){
alert("请选择要恢复的数据库备份文件!");
form1.path.focus();
return false;
}
if(!(extent2 == ".bak")){
window.alert("文件类型不正确!\n\n恢复文件后缀名应该为“.bak”!");
form1.path.focus();
return false;
}else{
window.location.href="db_restore.jsp?path="+extent;
}
}
</script>
</head>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master;user=sa");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select name from sysdatabases where name = 'MedicineERP'");
String pa = request.getParameter("path");
%>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="271" height="228" border="0" cellpadding="0"
cellspacing="0" background="../images/system/result.gif">
<tr>
<td height="57" align="center" valign="bottom"> 数据库恢复 </td>
</tr>
<tr>
<td height="34" valign="bottom" align="center"> 数据库备份文件名称: </td>
</tr>
<tr>
<td height="43" align="center"><input name="path" type="file" id="path"></td>
</tr>
<tr>
<td align="center" valign="bottom"> 选择需要恢复的数据库: </td>
</tr>
<tr>
<td align="center" valign="bottom">
<select name="select" id="select">
<%
if (rs.next()) {
String database = rs.getString(1);
out.println("<option id='" + database + "'>" + database
+ "</option>");
}
if (pa != null) {
st.executeUpdate("restore database Medicine from disk='" + pa + "'");
out
.print("<script language='javascript'>alert('恢复完成');</script>");
}
rs.close();
st.close();
conn.close();
%>
</select>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<input type="button" name="Submit" value="恢复" onclick="return check()">
</td>
</tr>
</table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -