Is your primary key generated automatically?
If so, the combined insert/query is:

           String stmt="INSERT INTO SOMEFILE (FLD1,FLD2,FLD3)
VALUES(?,?,?)";
           PreparedStatement sql =
conn.prepareStatement(stmt,Statement.RETURN_GENERATED_KEYS);
           sql.setInt(1,fld1);
           sql.setInt(2,fld2);
           sql.setInt(3,fld3);
           sql.execute();
           ResultSet rs = sql.getGeneratedKeys();
           if (rs.next()) {
              // get generated key
              int key=rs.getInt(1);
           }



|---------+-------------------------------->
|         |           "Mike Curwen"        |
|         |           <[EMAIL PROTECTED]|
|         |           ndless.com>          |
|         |                                |
|         |           01/10/2004 02:14 PM  |
|         |           Please respond to    |
|         |           "Tomcat Users List"  |
|         |                                |
|---------+-------------------------------->
  
>--------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                          |
  |       To:       "'Tomcat Users List'" <[EMAIL PROTECTED]>                          
             |
  |       cc:                                                                          
                          |
  |       Subject:  RE: method level synchronization doesn't work                      
                          |
  
>--------------------------------------------------------------------------------------------------------------|




Ok, since it's been brought forward...

how do you update and retrieve all in one query?  This is for: "I need a
new
primary key, and I need it to be thread safe."

something that would run on mysql?

unless you can get this magic query, it's not quite as simple as "let the
databse handle it", is it?


> -----Original Message-----
> From: Peter Lin [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 30, 2004 7:42 PM
> To: Tomcat Users List; [EMAIL PROTECTED]
> Subject: Re: method level synchronization doesn't work
>
>
> that would be the easiest way.
>
> but you made it too easy, I thought people are suppose to
> suffer and stumble :)
>
> peter
>
>
> On Thu, 30 Sep 2004 17:46:51 -0400, Frank W. Zammetti
> <[EMAIL PROTECTED]> wrote:
> > Why not just let SQL do the update?  Do the following:
> >
> > update my_table set counter_field = counter_field + 1 (where clause
> > here if needed)
> >
> > (off the top of my head, my syntax might be off)
> >
> > In other words, why not let the database handle the
> concurrency issue?
> > That's kind of what they're there for (partly anyway).
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to