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];
}
}
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]; } }