• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How must i "synchronize" my servlets?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm quite new to java servlets.. I wrote a web app where it uses a hsqldb database and the jdbc driver to access it.. I wrote a specific class which is not a servet to handle the database..



Is this how i must do it? Is it safe to synchronize all database access methods.. Will it slow down the web app?

And this class returns the result set object to be handled by the exact servlet.. Is it safe to do so? That way i won't be able to close the connection.. Please give me some advice.. Thank you..
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Malith,

In general it's a good thing to separate servlet from the jdbc/database related code.

I think it's better to define and use dbPath and conn only as local variables (inside the methods), and then you don't have to worry about synchronization.

on't return the resultset to the servlet:
-a servlet is for request/response, and should not have knowledge about how you store you data (rel. database or files or whatever)
-make sure you always close your connections, statements and resultsets
(do it in a finally block)

One more tip:
try to use connection pooling (with a datasource). It's faster and makes your code less dependant on a particular driver.

gr,
Herman
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!