Java SQL ResultSet Read getClassName(ResultSetMetaData meta, int index)

Here you can find the source of getClassName(ResultSetMetaData meta, int index)

Description

Returns a column's java class name.

License

Open Source License

Declaration

public static String getClassName(ResultSetMetaData meta, int index) throws SQLException 

Method Source Code

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

import java.sql.*;

public class Main {
    /**/*from w ww.ja v a  2s.c  o  m*/
     * Returns a column's java class name.
     */
    public static String getClassName(ResultSetMetaData meta, int index) throws SQLException {
        switch (meta.getColumnType(index)) {
        case Types.NUMERIC:
            int precision = meta.getPrecision(index);
            if (meta.getScale(index) == 0) {
                if (precision > 18) {
                    return "java.math.BigInteger";
                } else if (precision > 9) {
                    return "java.lang.Long";
                } else if (precision > 4) {
                    return "java.lang.Integer";
                } else if (precision > 2) {
                    return "java.lang.Short";
                } else {
                    return "java.lang.Byte";
                }
            } else {
                if (precision > 16) {
                    return "java.math.BigDecimal";
                } else if (precision > 7) {
                    return "java.lang.Double";
                } else {
                    return "java.lang.Float";
                }
            }
        case Types.TIMESTAMP:
            if (meta.getScale(index) == 0) {
                return "java.sql.Date";
            } else {
                return "java.sql.Timestamp";
            }
        default:
            return meta.getColumnClassName(index);
        }
    }
}

Related

  1. getBigIntegerFromResultSet(ResultSet rs, String db_name)
  2. getBigObject(ResultSet set, int columnIndex)
  3. getCalendar(ResultSet resultSet, String columnName)
  4. getCharacterStream(ResultSet resultSet, String columnName)
  5. getChunkDelimiters(ResultSet rs, int tsColumnIndex, int chunkSize)
  6. getCountFromResultSet(ResultSet rs)
  7. getData(final ResultSet rs)
  8. getDataDupls(ResultSet rs)
  9. getDateList(ResultSet resultSet, String columnName)