| Bug #1247 | ResultSet.get/setString mashing char 127 | ||
|---|---|---|---|
| Submitted: | 11 Sep 2003 6:54 | Modified: | 11 Sep 2003 10:23 |
| Reporter: | Brad Benesch | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S2 (Serious) |
| Version: | 3.0.8-stable | OS: | Windows (Win32) |
| Assigned to: | CPU Architecture: | Any | |
[11 Sep 2003 10:23]
Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.
If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information
about accessing the source trees is available at
http://www.mysql.com/doc/en/Installing_source_tree.html
[11 Sep 2003 10:23]
Mark Matthews
You can check out the fix from the nightly snapshot after 00:00 GMT Sept 12, at http://mmmysql.sourceforge.net/snapshots/

Description: I'm having a problem where a VARCHAR column containing character 127 returns a String with character 0. The workaround is to use new String(rs.getBytes(col)) instead of rs.getString(col). Also, rs.setString() changes char 127 (0x7F) to 0x3F. I am using 3.0.8-stable on Win32 - also seems to be a problem in 3.1.0-alpha. I believe the culprit is an incompletely initialized array byteToChars in SingleByteCharsetConverter. The code below, using BYTE_RANGE (=256) rather than Byte.MAX_VALUE - Byte.MIN_VALUE (=255) fixes this issue. If you have a better work-around, perhaps by explicitly setting the character encoding (default encoding seems to be ISO8859_1), please let me know. Brad How to repeat: Here is a sample table that illustrates the problem. Compare rs.getString(1) and new String(rs.getBytes(1)) -- MySQL dump 9.07 -- -- Host: aksun3 Database: OUSMDB --------------------------------------------------------- -- Server version 3.23.36 -- -- Table structure for table 'Test127' -- USE Test; CREATE TABLE Test127 ( value varchar(25) NOT NULL default '', ) TYPE=MyISAM; -- -- Dumping data for table 'AkaraNode' -- INSERT INTO Test127 VALUES ('*5bT,I.'); Suggested fix: /** * Prevent instantiation, called out of static method initCharset(). * @param encodingName a JVM character encoding * @throws UnsupportedEncodingException if the JVM does not support * the encoding */ private SingleByteCharsetConverter(String encodingName) throws UnsupportedEncodingException { String allBytesString = new String(allBytes, 0, BYTE_RANGE, encodingName); int allBytesLen = allBytesString.length(); System.arraycopy(unknownCharsMap, 0, charToByteMap, 0, charToByteMap.length); for (int i = 0; (i < BYTE_RANGE) && (i < allBytesLen); i++) { char c = allBytesString.charAt(i); byteToChars[i] = c; charToByteMap[c] = allBytes[i]; } }