批次导出Oracle文件
String sql = "select t.TABLE_NAME from user_tables t where num_rows=0";
PreparedStatement prep = null;
StringBuffer sb = new StringBuffer();
CallableStatement cs = null;
ResultSet resultSet = null;
try {
prep = conn.prepareStatement(sql);
resultSet = prep.executeQuery();
while (resultSet.next()) {
sb.append(resultSet.getString("TABLE_NAME") + ",");
}
} catch (Exception e) {
// TODO: handle exception
}
String a = sb.toString();
try {
FileWriter fileWriter = new FileWriter("C:/Users/Administrator/Desktop/list.sql");
int old = 0;
for (int i = 50; i < 6000; i += 50) {
// 这里是获取"/"符号的位置
Matcher slashMatcher = Pattern.compile(",").matcher(a);
int mIdx = 0;
while (slashMatcher.find()) {
mIdx++;
// 当"/"符号第三次出现的位置
if (mIdx == i) {
String c = a.substring(old, slashMatcher.start());
//C:\Users\Administrator\Desktop\sql
String d = "EXP scott/tiger@localhost:1521/orcl file= C:\\Users\\Administrator\\Desktop\\sql\\"+mIdx + ".dmp tables=( " + c + ")";
fileWriter.write(d + "\r\n");
old = slashMatcher.start()+1;
break;
}
}
}
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}