Try with resources or not?

Yup finally I settled down with a company or a job more precisely? A financial company which mainly handle stock transaction. Of course I have far more to learn in the near future and new challenge come every day.
Unlike the last one, I feel alive which work with tenanted colleague and work closely with each other to maintain the legit java base stock trading sys.
But alright just dun go too far for now. The topic this week is Try with Resources. Which is a Java 7 feature if Im not mistaking.

Thing happen like this, as the first week of the work. I got assigned for user enhancement, which mainly related to improve existing JSP page.

The story begin here, as the jsp page I worked establish a DB connection by JDBC then display content accordingly. The new enhance meant is about to let user enter two more column which would then send along with the existing insert statement. Ok that still alright.

So the first insight came into my mind is get creaking with code block of DB connection right? Simply add two input filed and add it according into existing statement. Of course notice DBA the change as well. Of course code refactor throughout the whole process….
Which is the best way for me to understand the structure of code. Hence check on the JDBC code. And the problem pop out. I am suppose to alter the existing try {} catch {} finally {} block into try( ) { } catch { } resource. However the business out their is kind of odd for me so I decide to share with u guys.
The original code block look like following?
Screen Shot 2017-03-20 at 12.32.38 AM
Sorry guy Im trying best to mimic the scene, but it been week ago but ya. But the problem in here is where should the commit / rollback code go once it refactor into try-with-resources? The usage of try-with-resources is to eliminate the finally block for us to make out life easier. However it turn out problem came in with more operation need to be done on finally block.
Should I move the commit / rollback into try ? but it may not be executed as exception pop out earlier than I expected.
How about Catch block. again it wouldn’t execute if the process ran smoothly.
Guess what, I end up keep the existing structure. Would review it once I got the solution may be? But definitely not now. Haaaaaaaaa
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s