Tuesday, 10 September 2013

New ResultSet with a where, or move cursor to beginning and check condition manually

New ResultSet with a where, or move cursor to beginning and check
condition manually

I am going to be given a staging table, which I run a process to load the
data into a bigger table, and remove data from the staging table. Some
rows in the staging table, denote deletions of rows in the main table
though.
Right now the algorithms is as follows:
ResultSet dataToLoad = select * from ...;
ResultSet mainTable = select * from ...;
while dataToLoad.next()
{
if(insert)
//insert this row into main table, and remove row from this table
else if(delete)
//Find the row that matches in the main table and delete it.
remove row from this table
}
My question is for the delete block. Would it be best to make a new
ResultSet to find the row using a where and just delete the single row in
the set, or to put the cursor to the beginning and loop through the cursor
checking conditions? Essentially like implementing a where clause in java
code.
How much does JDBC cache when you load in a ResultSet? is it going to do a
full network round trip for each cursor jump?
Lastly, I read up briefly on the Halloween Problem. Am I at risk of that
here?

No comments:

Post a Comment