我有一种从 MySQL 数据库中提取和清理数据的方法。
该过程的下一步是将这些数据移至 Oracle 数据库。
但是,在从 MySQL 提取和清理数据的过程中,我与 oracle 数据库有一个连续的连接。这是不必要的,并且会极大地减慢提取过程。
如何让 java 等待提取/清理过程完成,然后连接到 Oracle?
这是我的代码:
public void ConvertFiles() {
try {
connectToDB();
RawFile tempFile = new RawFile(super.mFileType);
try {
ArrayList<String> values = new ArrayList<String>();
try {
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM coffeedata");
int ii = 0;
while (result.next()) {
ii++;
System.out.print("Reading Row:" + ii + "/" + 41429 + "\n");
mStore = (result.getString(1));
mCategory = (result.getString(2));
mName = (result.getString(3));
// Add columns 2007 Q1 - Q4 t/m 2009 Q1 - Q2 to ArrayList
for (int i = 4; i < 14; i++) {
values.add("" + result.getInt(i));
}
tempFile.addData(new SQLData(mCategory, mName, values, mStore));
try {
OracleController.DataToOracle();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
tempFile.CleanCategory();
mRawFiles.add(tempFile);
} catch (Exception e) {
System.out.println(e.getMessage());
closeDBConnection();
}
} catch (Exception e) {
System.out.println(e.getMessage());
//return values;
//System.out.println(values);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
澄清一下:我想让这个 Try 等到前一个完成为止:
try {
OracleController.DataToOracle();
}
最佳答案
重构您的代码,并将您的 try
block 放置在您想要等待的 try - catch - finally
之后。
try{
//block that you need to excecute before
} catch { ... }
// Than your block
try {
OracleController.DataToOracle();
} catch (Exception e)
}
关于java - 让Java等待之前的Try完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13887755/