You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "p@zdzior" <pa...@interia.pl> on 2003/08/25 13:52:13 UTC

SQL INSERT

Dear Taglibs users,

I am erforming SQL insert statement using  JSTL tgalib:

   <sql:transaction dataSource="${test}">
      <sql:update var="InsertDriver">
        INSERT INTO REQUEST_OFFER (RO_FK_CUST_PHONENO, RO_TYPE
                                   VALUES (?,?)
        <sql:param value="${Customer.phone_no}"/>
        <sql:param value="SINGLE"/>
      </sql:update>
    </sql:transaction>
 
The REQUEST_OFFER table has an ID field which is autincrement unique key.
Is it possible to obtain the value of this filed just after insert using JSTL?
Something like getGeneratedKeys() java methd.
Or if it is impossible to do using JSTL how to do it using java scriptlet?

thank you very much for help,

regards,
lukasz




Re: SQL INSERT

Posted by Serge Knystautas <se...@lokitech.com>.
p@zdzior wrote:
>    <sql:transaction dataSource="${test}">
>       <sql:update var="InsertDriver">
>         INSERT INTO REQUEST_OFFER (RO_FK_CUST_PHONENO, RO_TYPE
>                                    VALUES (?,?)
>         <sql:param value="${Customer.phone_no}"/>
>         <sql:param value="SINGLE"/>
>       </sql:update>
>     </sql:transaction>
>  
> The REQUEST_OFFER table has an ID field which is autincrement unique key.
> Is it possible to obtain the value of this filed just after insert using JSTL?
> Something like getGeneratedKeys() java methd.
> Or if it is impossible to do using JSTL how to do it using java scriptlet?

The JSTL SQL tags just run SQL statements... there's nothing fancy going 
on here.  Usually there's a database function you can call, select 
SELECT last_id() or something like that, to retrieve the ID of the most 
recently auto-incremented key value.

You'll want this second SQL statement to happen in the connection, but 
since you're using the sql:transaction tag, that will already happen.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com