Java SQL Type getColumnType(String type)

Here you can find the source of getColumnType(String type)

Description

Get the concrete column value type for a standard data type.

License

Open Source License

Parameter

Parameter Description
type the fully qualified Java data type of the attribute

Return

a string representation of a JDBC method call

Declaration

public static String getColumnType(String type) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String JAVA_STRING = "java.lang.String";
    private static final String UUID = "java.util.UUID";
    private static final String JAVA_BIG_INTEGER = "java.math.BigInteger";
    private static final String JAVA_BIG_DECIMAL = "java.math.BigDecimal";

    /**//  w w w.j  av  a  2 s .  co  m
     * <p>
     * Get the concrete column value type for a standard data type. The concrete
     * column type is a concrete subclass of AbstractColumn and provides column
     * support for primary keys. This method supports the following data types:
     * </p>
     * <ul>
     * <li>BigDecimal--BigDecimalColumnValue</li>
     * <li>BigInteger--BigIntegerColumnValue</li>
     * <li>Integer--IntegerColumnValue</li>
     * <li>Long--LongColumnValue</li>
     * <li>String--StringColumnValue</li>
     * <li>Date--DateColumnValue</li>
     * <li>Timestamp--TimestampColumnValue</li>
     * <li>UUID--UuidColumnValue</li>
     * </ul>
     * 
     * @param type the fully qualified Java data type of the attribute
     * 
     * @return a string representation of a JDBC method call
     */
    public static String getColumnType(String type) {
        if (type == null) {
            throw new RuntimeException("Null data type while getting JDBC get call");
        }

        // Implement all supported types here.
        String valueType = null;
        if (type.equals(JAVA_BIG_INTEGER)) {
            valueType = "BigIntegerColumnValue";
        } else if (type.equals(JAVA_STRING)) {
            valueType = "StringColumnValue";
        } else if (type.equals(JAVA_BIG_DECIMAL)) {
            valueType = "BigDecimalColumnValue";
        } else if (type.equalsIgnoreCase("java.lang.Integer")) {
            valueType = "IntegerColumnValue";
        } else if (type.equalsIgnoreCase("java.lang.Long")) {
            valueType = "LongColumnValue";
        } else if (type.equals("java.sql.Date")) {
            valueType = "DateColumnValue";
        } else if (type.equals("java.sql.Timestamp")) {
            valueType = "TimestampColumnValue";
        } else if (type.equals(UUID)) {
            valueType = "UuidColumnValue";
        } else if (type.contains("java.util.List") || type.contains("java.util.Collection")) {
            // to-many attributes of List and Collection don't come from result set
            valueType = null;
        } else {
            throw new RuntimeException("Unsupported Java type " + type + " for key column value type ");
        }
        return "com.poesys.db.col." + valueType;
    }
}

Related

  1. getClassByJdbcType(int type, int decimalDigits)
  2. getCloverTypeFromJdbcType(int jdbcDataType)
  3. getColumeTypeDesc(Class clazz)
  4. getColumnClass(int sqlType)
  5. getColumnType(Connection conn, String table, String column)
  6. getConnection(String jdbcUrl, Properties properties)
  7. getDbDataType(Object o)
  8. getDefaultPrecision(int sqlType)
  9. getDefaultScale(int sqlType)