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 Don Coleman <do...@emax.com> on 2001/10/19 21:10:39 UTC
DBtag problem using PreparedStatement
I am having a problem with PreparedStatments and DB-tags 1.0 Beta 1
The following page (see below for full page) will not return any results
when using this query
<sql:query>
SELECT sku, product_ds FROM deo_product where sku = ?
</sql:query>
<sql:setColumn position="1">K17</sql:setColumn>
But if I use like it works fine.
<sql:query>
SELECT sku, product_ds FROM deo_product where sku like ?
</sql:query>
<sql:setColumn position="1">K1%</sql:setColumn>
I'm not sure what I am doing wrong. I've tried adding quotes and using
<sql:escapeSql> but I can't get this to work.
Does anyone have any suggestions?
<%@ taglib uri="http://jakarta.apache.org/taglibs/dbtags" prefix="sql" %>
<%-- open a database connection --%>
<sql:connection id="conn" jndiName="java:/comp/env/jdbc/deo"/>
<%-- print the rows in an HTML table --%>
<table>
<sql:preparedStatement id="stmt" conn="conn">
<sql:query>
SELECT sku, product_ds FROM deo_product where sku = ?
</sql:query>
<sql:setColumn position="1">K17</sql:setColumn>
<%-- loop through the rows of your query --%>
<sql:resultSet id="rs">
<tr>
<td><sql:getColumn position="1"/></td>
<td><sql:getColumn position="2"/></td>
</tr>
</sql:resultSet>
</sql:preparedStatement>
</table>
<!-- close the connection -->
<sql:closeConnection conn="conn"/>