I have a method that extracts and cleans data from a MySQL database.
Next step in the process is moving this data to Oracle database.
However, during the process of extracting and cleaning the data from MySQL, I have a coninous connection to the oracle db. This is not nescessary and extremely slows down the extraction process.
How do I let java wait till the extracion/cleaning processes are complete and THEN make a connection to Oracle?
This is my code:
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());
}
For clarification: I want to let this Try wait till the previous one is completed:
try {
OracleController.DataToOracle();
}
Refactor your code and place your
tryblock aftertry - catch - finallythat you want to wait.