Bug #1938 ODBC won't return single character strings
Submitted: 24 Nov 2003 15:58 Modified: 28 Nov 2003 12:55
Reporter: David Mitchell Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51.06 OS:Microsoft Windows (Windows 2000)
Assigned to: CPU Architecture:Any

[24 Nov 2003 15:58] David Mitchell
Description:
I was using Apache Tomcat 4.1.27, Mysql 4.0.15 and MyODBC 3.51.06 to develop a simple database application in Windows 2000.  I was doing a Query which retrieved all of the records from the database and I found that if a String type field had only one character in it, such as "a", the value would not be returned.  It just came up blank as if nothing was in the field at all.

Through some experimentation, I came to suspect that MySQL connector was the problem, so I tried installing an older version (mysqlodbc 2.5) and the database is returning single character fields as expected now.

How to repeat:
This test program written in JSP should do the trick - just insert a record with only one character in the "field_name" field.  If I'm right, that field should turn up blank when you run this:

Driver drv = (Driver)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:modem");
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT * FROM database_name");

String name;
		
while ( results.next() ) {
  name = results.getString("field_name");
  out.println("Name: " + name + "<br />");
}

stmt.close();
conn.close();

Suggested fix:
Eek!  I have no idea, I just thought I should bring this to your attention.  I'm assuming that there's a loop somewhere that isn't doing it's job quite right, but I am not familiar with the code for MyODBC.  Sorry about that, I figure it's better to report this than let it fester.
[28 Nov 2003 12:55] Dean Ellis
I am unable to duplicate this using Tomcat 4.1.29 (or 5.0.14) with MyODBC 3.51.06 and MySQL 4.0.17, using Sun's 1.4.2 SDK.  I tried with char, varchar and text column types as well.

Your code works essentially as written, so it would appear that the problem is not in MyODBC.