Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection attempt

 
Dan Parsons
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a good way to insert and update into a database or is there anything I can improve?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
Two things jump out at me:
1) The statement resource is never closed. This should be closed in a finally block to release resources. Otherwise, you are hoping the garbage collector will clean it up for you. This is fine for memory. For a valuable database resource, it is problematic.
2) The code is brittle if it isn't called exactly the way you expect. If you are just experimenting, this is fine. If you are going to have to maintain the code, it is difficult. For example, what if the caller doesn't call finally? (resource leak) What if connection is null? (the method just silently does nothing)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic