File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "getCharacterStream puzzler" Watch "getCharacterStream puzzler" New topic

getCharacterStream puzzler

Dave Bender

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.
Joe Ess

Joined: Oct 29, 2001
Posts: 9188

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

Because it returns an instance of 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]
I agree. Here's the link:
subject: getCharacterStream puzzler
jQuery in Action, 3rd edition