tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jthomp...@honda.co.nz
Subject RE: method level synchronization doesn't work
Date Fri, 01 Oct 2004 04:05:53 GMT






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"        |
|         |           <g_dev9xq@globallybou|
|         |           ndless.com>          |
|         |                                |
|         |           01/10/2004 02:14 PM  |
|         |           Please respond to    |
|         |           "Tomcat Users List"  |
|         |                                |
|---------+-------------------------------->
  >--------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                       |
  |       To:       "'Tomcat Users List'" <tomcat-user@jakarta.apache.org>         
                             |
  |       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:woolfel@gmail.com]
> Sent: Thursday, September 30, 2004 7:42 PM
> To: Tomcat Users List; fzlists@omnytex.com
> 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
> <fzlists@omnytex.com> 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: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message