Example usage for org.apache.commons.dbutils.wrappers SqlNullCheckedResultSet setNullString

List of usage examples for org.apache.commons.dbutils.wrappers SqlNullCheckedResultSet setNullString

Introduction

In this page you can find the example usage for org.apache.commons.dbutils.wrappers SqlNullCheckedResultSet setNullString.

Prototype

public void setNullString(String nullString) 

Source Link

Document

Sets the value to return when a SQL null is encountered as the result of invoking a getString method.

Usage

From source file:dbutils.ExampleJDBC.java

/**
 * Unlike some other classes in DbUtils, this class(SqlNullCheckedResultSet) is NOT thread-safe.
 *//* w  ww. j  a v a  2  s  .co m*/
public static void findUseSqlNullCheckedResultSet() {
    Connection conn = getConnection();
    try {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT id, name, gender, age, team_id as teamId FROM test_student");
        SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(rs);
        wrapper.setNullString("N/A"); // Set null string
        rs = ProxyFactory.instance().createResultSet(wrapper);

        while (rs.next()) {
            System.out.println("id=" + rs.getInt("id") + " username=" + rs.getString("name") + " gender="
                    + rs.getString("gender"));
        }
        rs.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
}