Java Quick Tip Of the Day: Character Encoding and ResultSets

We recently ran into a problem where a Java program running on our IBM enterprise server was unable to properly display strings returned from a Microsoft SQL Server table. The problem was due to character encoding. Because of the SQL Server table definition, the JDBC driver was not translating the ASCII values in the string returned from a ResultSet.getString() method to EBCDIC.

The solution. Explicitly define the encoding by casting the returned value of a ResultSet.getBytes() into a String (see below).

String outStr =  new String(rs.getBytes(1),"ISO-8859-1");

About Rick
Many years of technology experience working in both the public and private sector. I hold undergraduate degrees in Information Systems and Management as well as a Master in Business Administration. Currently I'm Vice President of Information Technology for Thomas Nelson Publishers, Inc.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: