Ah that depends on the SQL statement and the primary keys of whatever
table you were interested.
Are you are talking about a UPDATE <TABLE> or INSERT TABLE <TABLE>?
You are have make sure that your database design is integral. Have
order number, customer no, ticket no as primary keys for your reservation system
in order to avoid duplications of order, customers, and tickets.

But back on topic. The database will have transaction locks on it already to
avoid corruption. The servlet does not need synchronization normally
accept if you updating an incremental reference. Then you need
to lock you method thus that has try/catch/finally handling.

aLock = getDatabaseLockObject();
sychronized ( aLock ) {
     Connection conx = .DBPool.acquire();
     Statement stmt = conx.createStatement();
     boolean saved = conx.getAutoCommit();
     conx.setAutoCommit(false);
     try {
          String sql1 = "select NEXT_VALUE from REFERENCE_TABLE "+
               "where REFERENCE_NAME='NEXT_KEY_TicketID'";
          ResultSet rs = stmt.executeQuery(sql1 );
          int NEXT_KEY_TicketID = rs.getInt(1)+2;
          String sql2 = "update REFERENCE_TABLE set NEXT_VALUE "+
               "where REFERENCE_NAME='NEXT_KEY_TicketID'";
          stmt.execute(sql2 );
     }
     catch (SQLException se) {
          conx.rollback();
     }
     finally(
          conx.setAutoCommit(saved);
     }
}
--

Peter Pilgrim
Welcome to the "Me Too" generation.


---------------------------------------- Message History 
----------------------------------------


From: [EMAIL PROTECTED] on 10/10/2000 11:22

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:
Subject:  Re: Synchronize method in the servlet



would the DB's will not have an internal lock for their operations??.  is it
mandatory to make the DB object static for DB operations.

For example in an online reservation system if you have only one ticket left
and 2 users are trying to reserve at the same milliseconds i believe DB will
not entertain both of their request.  Am i right??.

Cheers
Srini

-----Original Message-----
From: Raj Kumar Jha [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 10, 2000 11:33 AM
To: [EMAIL PROTECTED]
Subject: Re: Synchronize method in the servlet





--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to