• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Connection attempt

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?

author & internet detective
Posts: 39994
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic