File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlets with datadase interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets with datadase interaction" Watch "servlets with datadase interaction" New topic

servlets with datadase interaction

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
my question is what precautions i have to take while coding servlets which has data manipulation commands.
I have written a piece of code inside a doGet() method of a servlet.that code interacts with database ie. the code updates a record and insert a record.if thousands of people accessing the same servlent at the same time what will happen. will that servlet process all requests or will it throw an Exception.Do I have to take any care while writing this kind of code in a servlet.I want to avoid synchronization or synchronized block b'cos due to synchronization the servlet the servlet can't serve multiple clients at the same time.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
You will probably be all right. All modern databases support the concept of "transactions", groups of operations which mustn't be interrupted. As long as you make sure that all database operations which your servlet performs during a single request are grouped as a transaction, then the database should be able to handle many simultaneous accesses without getting confused.
For performance reasons, I would also recommend that you look into database connection pooling. If you continually have several servlets trying to access the database at once, you really don't want the overhead of opening a new connection for every request.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
wood burning stoves
subject: servlets with datadase interaction
It's not a secret anymore!