Java SQL Table Column getColumnValue(ResultSet rs, ResultSetMetaData rsmd, int colIndex)

Here you can find the source of getColumnValue(ResultSet rs, ResultSetMetaData rsmd, int colIndex)

Description

get Column Value

License

Open Source License

Declaration

private static String getColumnValue(ResultSet rs,
            ResultSetMetaData rsmd, int colIndex) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.*;

public class Main {
    private static String getColumnValue(ResultSet rs,
            ResultSetMetaData rsmd, int colIndex) throws SQLException {

        String s = rs.getString(colIndex);
        if (rs.wasNull())
            return "null";

        switch (rsmd.getColumnType(colIndex)) {
        case Types.BIT: // bool or bit(n)
            if (s.equals("t") || s.equals("f"))
                return String.valueOf(rs.getBoolean(colIndex));
            else//from   ww w.  j av a  2  s.c  o m
                return s;
        case Types.DATE: // date
            return rs.getDate(colIndex).toString();
        case Types.TIME: // time or timetz
            return rs.getTime(colIndex).toString();
        case Types.TIMESTAMP: // timestamp or timestamptz
            return rs.getTimestamp(colIndex).toString();
        default:
            return s;
        }
    }
}

Related

  1. getColumnsNames(ResultSet rs)
  2. getColumnType(ResultSet resultSet, int i, Map typeCache)
  3. getColumnType(ResultSetMetaData rsm)
  4. getColumnType(ResultSetMetaData rsmd, int idx)
  5. getColumnTypes(ResultSet rs)
  6. getColumnValue(String column, String defaultValue, Map columnIndexMap, ResultSet res)
  7. getColumnValueFromResultSet(int columnIndex, int argType, ResultSet rs)
  8. getColunmNames(ResultSetMetaData rsmd)
  9. getIndexColumns(Connection connection, String schema, String table, String indexName)