Prepared Statement bug?
Posted by: Connor Barry
Date: May 07, 2005 05:20PM

I think there's a bug in the driver.

My JSP code:
Connection con = DriverManager.getConnection(

PreparedStatement stmt = con.prepareStatement("select doc0_.item_id as id, doc0_1_.version as version1_, " +
"doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, " +
"doc0_1_.on_sale as on6_1_, as name3_, as active3_, " +
"doc0_.abstract_text as abstract4_3_" +
" from document_items doc0_ inner join items doc0_1_ on" +
" where doc0_.item_id = ?");
ResultSet rs = stmt.executeQuery();
while ( {%>
Doc: <%=rs.getString("id")%> - <%=rs.getString("name3_")%>
<% }

stmt = con.prepareStatement("select childcateg0_.parent_id as parent5___, as id__, " +
" as id0_, childcateg0_.version as version13_0_, childcateg0_.created as created13_0_," +
" as name13_0_, childcateg0_.parent_id as parent5_13_0_ from categories childcateg0_" +
" where childcateg0_.parent_id = ?");
rs = stmt.executeQuery();
while ( {%>
Cat: <%=rs.getString("id__")%> - <%=rs.getString("name13_0_")%>
<% }

Basically, I'm preparing two statement, each with one parameter. In both statements I set the parameter to a valid ID. The first one returns no rows, the second one returns two results.

If I change the queries to normal queries (by typing in the value of each parameter in the place of the "?"), the first query then returns one row.

I'm using Connector/J 3.1.8a and MySQL 4.1.11-nt-max
I tried the same code using Connector/J 3.2alpha, same results.

My workaround will be to append the following to the connection URL of my datasource:

Options: ReplyQuote

Written By
Prepared Statement bug?
May 07, 2005 05:20PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.