Bug #17450 | ResultSet.getBoolean() doesn't always set the wasNullFlag | ||
---|---|---|---|
Submitted: | 16 Feb 2006 11:29 | Modified: | 5 Apr 2006 20:13 |
Reporter: | Karel Vervaeke | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 3.1.11, 3.1.12 | OS: | Windows (Windows 2k) |
Assigned to: | Mark Matthews | CPU Architecture: | Any |
[16 Feb 2006 11:29]
Karel Vervaeke
[17 Feb 2006 9:11]
Karel Vervaeke
The section "Perform the following steps" in the description isn't very clear. Here's a better version: Perform the following steps: first do "insert into booleanbug (FOO,BAR) values (null,true)" then: ResultSet rs = pst.executeQuery() rs.getString(1); System.out.println(rs.wasNull()); // prints true (as expected) rs.getBoolean(2); System.out.println(rs.wasNull()); // prints true (which is wrong)
[21 Feb 2006 16:16]
Karel Vervaeke
Duplicate of 4689, works with 3.1.12
[21 Feb 2006 16:21]
Karel Vervaeke
Oops! does *not* work with 3.1.12 (sorry!)
[27 Mar 2006 11:28]
Tonci Grgin
Thanks for your bug report. Verified on XP SP2 as described by reporter. import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.sql.PreparedStatement; public class Main { Connection con; public void setUp() throws Exception { Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://munja/test","root",""); Statement st = con.createStatement(); st.execute("drop table if exists booleanbug"); st.execute("create table booleanbug (FOO VARCHAR(100), BAR CHAR NOT NULL)"); st.execute("delete from booleanbug where 1=1"); st.execute("insert into booleanbug (foo,bar) values ('foo',true)"); st.execute("insert into booleanbug (foo,bar) values (null,true)"); } public void tearDown() throws Exception { con.close(); } public void testPreparedStatement1() throws Exception { PreparedStatement st = con.prepareStatement("select * from booleanbug where foo=?"); st.setString(1,"foo"); testResult(st.executeQuery()); } public void testPreparedStatement2() throws Exception { PreparedStatement st = con.prepareStatement("select * from booleanbug where foo is null"); testResult(st.executeQuery()); } public void testStatement1() throws Exception { Statement st = con.createStatement(); testResult(st.executeQuery("select * from booleanbug where foo='foo'")); } public void testStatement2() throws Exception { Statement st = con.createStatement(); testResult(st.executeQuery("select * from booleanbug where foo is null")); } private void testResult(ResultSet rs) throws Exception { rs.next(); rs.getString(1); boolean bar = rs.getBoolean(2); System.out.println(bar + "/" + rs.wasNull()); } //constructor for class public Main() { try { setUp(); testPreparedStatement1(); testPreparedStatement2(); testStatement1(); testStatement2(); } catch(Exception e1) { e1.printStackTrace(); } finally { try { tearDown(); } catch(Throwable t){} } } //main function public static void main(String args[]) { new Main(); } } Console output: run: true/false true/true true/false true/false
[3 Apr 2006 20:06]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/4427