import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
List row = new ArrayList();
for (int i = 1, length = columns.size(); i <= length; i++) {
String value = null;
- if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) {
- value = getEncodedString(set, getEncoding(), i);
- } else {
- try {
+ try {
+ if (set.getMetaData().getColumnType(i) == java.sql.Types.LONGVARBINARY) {
+ value = getEncodedStringFromBinaryStream(set, getEncoding(), i);
+ } else if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) {
+ value = getEncodedString(set, getEncoding(), i);
+ } else {
if ("".equals(getEncoding())) { //$NON-NLS-1$
value = getStringFromCharacterSteam(set, i);
} else {
value = getEncodedStringFromBinaryStream(set, getEncoding(), i);
}
- } catch (IOException e) {
- value = set.getString(i);
- } catch (RuntimeException e) {
- // hack for mysql which doesn't implement
- // character streams
- value = set.getString(i);
}
+ } catch (IOException e) {
+ value = set.getString(i);
+ } catch (RuntimeException e) {
+ // hack for mysql which doesn't implement
+ // character streams
+ value = set.getString(i);
}
- if (value == null) {
+ if (value == null && !set.wasNull()) {
value = set.getString(i);
}
row.add(value == null || set.wasNull() ? "<NULL>" : value); //$NON-NLS-1$
} finally {
binaryStream.close();
}
- return new String(baos.toByteArray(), encoding);
+ if ("".equals(encoding))
+ return new String(baos.toByteArray());
+ else
+ return new String(baos.toByteArray(), encoding);
} else {
return null;
}
}
}
-
/**
* @param set
* @param encoding
private String getEncodedString(ResultSet set, String encoding, int index)
throws SQLException {
try {
- return encoding == null || encoding.trim().length() == 0
- ? set.getString(index)
- : new String(set.getBytes(index), encoding);
+ if (encoding == null || encoding.trim().length() == 0) {
+ return set.getString(index);
+ }
+ byte[] colBytes = set.getBytes(index);
+ if (colBytes == null) return null;
+ else return new String(colBytes, encoding);
} catch (UnsupportedEncodingException e) {
return set.getString(index);
}