aspose file tools*
The moose likes JDBC and the fly likes getCharacterStream puzzler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getCharacterStream puzzler" Watch "getCharacterStream puzzler" New topic
Author

getCharacterStream puzzler

Dave Bender
Greenhorn

Joined: Oct 16, 2003
Posts: 3
Why does the ResultSet.getCharacterStream().read method return an int instead of a Character?
It seems that that requires me to make the conversion of a number to a character, which aside from being error-prone, bypasses all the great character set translation stuff built into Java, doesn't it?
I'm interested in this topic mostly because I've got a problem with a JDBC driver returning question marks for certain extended characters and it seems like it has something to do with the number-to-character conversion.
Any insight, particularly on ways to make the conversion correctly, would be appreciated. I've got windows-1252 characters from Windows machines being stored as UNICODE characters (MS Access 2000; memo field) and they seem to be getting converted when they go through my servlet and JDBC driver to ISO-8859-1 characters. So many extended charcters, like the en- and em-dash characters, get turned into question marks.
Dave
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Originally posted by Dave Bender:
Why does the ResultSet.getCharacterStream().read method return an int instead of a Character?
Dave

Because it returns an instance of java.io.Reader. By returning the onen of the lowest-level objects in the IO hierarchy it gives you great flexability with how you implement your code. Java IO streams are very powerful, but not very intuitive. I suggest you check out this
tutorial for more information. In your case you probably want to create an instance of BufferedReader using the ResultSet.getCharacterStream() and use the readLine() method to read a memo field.


[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getCharacterStream puzzler