Getting a character from a database result set in Java.


As straight forward as it should be, getting a single character value from a database in Java isn’t very obvious.  The following code snippet demonstrates how you can do it.

ResultSet rs = Database.execute("some query");
char[] cbuf = new char[1];
rs.getCharacterStream("char_column").read(cbuf);
char theValue = cbuf[0];
String theValueAsAString = Character.toString(theValue);
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s