Dan,

If you serialize access via an UPDATE statement first, you can control
concurrency so:

stmt.executeUpdate("UPDATE CUSTOMERS SET id = (SELECT MAX(ID+1) FROM
CUSTOMERS)");
ResultSet rs = stmt.executeQuery("SELECT MAX(ID) FROM CUSTOMERS");

Dave Wolf
Internet Applications Division
Sybase


> -----Original Message-----
> From: A mailing list for Enterprise JavaBeans development
> [mailto:[EMAIL PROTECTED]]On Behalf Of Dan Hinojosa
> Sent: Monday, September 11, 2000 10:45 AM
> To: [EMAIL PROTECTED]
> Subject: Concurrency.
>
>
> Well lets say I have a customers table.  In a session bean I have this
> function that creates an ID for me.  Do I have concurrency problems with
> this?
>
> private int getID() throws SQLException, NamingException {
>     Connection conn = getConnection();
>     Statement stmt = conn.createStatement();
>     ResultSet rs = stmt.executeQuery("SELECT MAX(ID+1) FROM CUSTOMERS");
>
>     rs.next();
>     int i = rs.getInt(1);
>     stmt.close();
>     return i;
> }
>
> It works like a champ.  Granted I need better handling of the
> Exceptions.  But the question is concurrency will this pose a problem?
>
> P.S. If anyone is a manager of this newsgroup I always get a legg@...
> someone or rather is not a valid email box.  Can someone drop this
> person?
>
> --
>
> Dan Hinojosa
> Java & Lotus Notes Consultant
> Java Certified Programmer
>
> P.O. Box 4675
> Albuquerque, NM 87196-4675
> Telephone: (505) 262-0911
> Email: [EMAIL PROTECTED]
> WWW: http://www.digitalpriest.com
>
> ==================================================================
> =========
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to