Java SQL ResultSet String Read getStringUTF8(ResultSet rs, String which)

Here you can find the source of getStringUTF8(ResultSet rs, String which)

Description

get String UTF

License

Open Source License

Declaration

public static String getStringUTF8(ResultSet rs, String which) throws SQLException 

Method Source Code

//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.sql.ResultSet;

import java.sql.SQLException;

public class Main {
    public static boolean db_Derby = false;

    public static String getStringUTF8(ResultSet rs, String which) throws SQLException {
        if (db_Derby) { // unicode
            String str = rs.getString(which);
            if (rs.wasNull())
                return null;
            return str;
        }//  w  ww  .  ja  v a2  s . c o m
        byte rv[] = rs.getBytes(which);
        if (rs.wasNull())
            return null;
        if (rv != null) {
            String unicode;
            try {
                unicode = new String(rv, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                throw new InternalError(e.toString());
            }
            return unicode;
        } else {
            return null;
        }
    }

    public static final String getStringUTF8(ResultSet rs, int which) throws SQLException {
        if (db_Derby) { // unicode
            String str = rs.getString(which);
            if (rs.wasNull())
                return null;
            return str;
        }
        byte rv[] = rs.getBytes(which);
        if (rs.wasNull())
            return null;
        if (rv != null) {
            String unicode;
            try {
                unicode = new String(rv, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                throw new InternalError(e.toString());
            }
            return unicode;
        } else {
            return null;
        }
    }
}

Related

  1. getString(ResultSet rs, String name, String ifnull)
  2. getStringChunks(ResultSet rs, int colIndex, StringBuffer buf)
  3. getStringFromResultSetEmptyIsNull(ResultSet rset, String fieldName)
  4. getStringList(ResultSet resultSet, String columnName)
  5. getStringSuppressSQLException(final ResultSet rs, final String columnLabel)
  6. getStringValue(final ResultSet rs, final int index)
  7. getTrimmedStringToUpperCase(ResultSet rs, String columnLabel)