My class makes a remote connection to an iseries machine. I need to check the existance of a file. I use SQL Select to do that. If the file exists I stop my code and tell the user to wait until this file has been processed by accounting. The code needs to proceed if the file does not exist. My code will use SQL to create the file and populate it with data.
When using try and catch if my code detects that a file does not exist it stops processing as expected. How can I make the exception thrown about the none-existant file be okay and finish processing the rest of my code?
It is also possible to provide too much extra information. For example, if you have a 500 line program, go through it and only post the relevant pieces. Try to narrow your problem down as much as possible.
Wrap your execute call in a try-catch block. Catch the exception and set some variable to indicate if the file exists or not. Is there a more graceful way to figure out if the file exists or not? Is there a table you can query that lists available files (there are such tables-of-tables in Oracle).
And this may be a good opportunity to think about moving the SQL code into a DataAccessObject that hides the gory details from the business logic. You might try to change your code so the class you provide can look like this:
The class you provided may very well be the DAO object, but it is smart to split the SQL code from the non-SQL logic when you can, so take the different statements that need to be run, put them in their own methods, and handle any exceptions internal to those methods. Pass the exceptions on in a meaningful way if they can't be dealt with inside the method.
In the case of the shpdsk2 table not existing, it looks like you are handling that as a normal situation, so it would be caught in the method and not passed on (though avoiding it is better as the others have said).