tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kralidis,Tom [Burlington]" <Tom.Krali...@ec.gc.ca>
Subject SQL insert problem
Date Fri, 01 Apr 2005 19:07:10 GMT

Hi,

I have a JSTL bit of code which parses an XML document and inserts
selected element values into a PostgresSQL DB.  I use a forEach to loop
through a bunch of elements.  Within the forEach I run an
sql:transaction to insert the records.

The problem, on the inserts, is that the values getting put into the DB
are always from the first iteration of the loop.  When printing them out
in the loop via x:out I get back the correct data, but always the same
values on the inserts.

Code e.g. below (FC2, Tomcat 5.0.25).

Any idea what's going on?  Suggestions valued.

Thanks

..Tom


<%@page contentType="text/html"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x"  uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="sql"  uri="http://java.sun.com/jsp/jstl/sql" %>

<sql:setDataSource var="ds" scope="application"
driver="org.postgresql.Driver" url="jdbc:postgresql:mydb" user="u"
password="p"/>

<c:set var="requestURL" scope="page" value="http://[host]/somedoc.xml"/>

<c:import url="${requestURL}" varReader="xmlSource">
 <x:parse var="doc" xml="${xmlSource}" scope="page" />
</c:import>

<html>
 <head>
  <title>test</title>
 </head>
 <body>
<x:forEach select="//Layer" var="$layer">
 <p>Title: <x:out select="$layer/Title"/></p>
 <sql:transaction dataSource="${ds}">
  <sql:update var="ud">
   insert into service_resources (title) values ('<x:out
select="$layer/Title"/>')
  </sql:update>
 </sql:transaction>
 <p>Inserting layer into database END</p>
</x:forEach>
 </body>
</html>


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


Mime
View raw message