Java Utililty Methods SQL Type

List of utility methods to do SQL Type

Description

The list of methods to do SQL Type are organized into topic(s).

Method

StringgetColumeTypeDesc(Class clazz)
get Colume Type Desc
String result;
if (clazz == boolean.class || clazz == Boolean.class) {
    result = "bit";
} else if (clazz == short.class || clazz == Short.class) {
    result = "smallint(4)";
} else if (clazz == int.class || clazz == Integer.class) {
    result = "int(11)";
} else if (clazz == long.class || clazz == Long.class) {
...
ClassgetColumnClass(int sqlType)
This method return the Class of a specific SQL Type, defined in java.sql.Types.
switch (sqlType) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
    return String.class;
case Types.BIT:
case Types.BOOLEAN:
    return boolean.class;
...
intgetColumnType(Connection conn, String table, String column)
Returns the type (as specified in java.sql.Types for the specified column in the specified table.
ResultSet rs = getColumnMetaData(conn, table, column);
try {
    return rs.getInt("DATA_TYPE");
} finally {
    rs.close();
StringgetColumnType(String type)

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

if (type == null) {
    throw new RuntimeException("Null data type while getting JDBC get call");
String valueType = null;
if (type.equals(JAVA_BIG_INTEGER)) {
    valueType = "BigIntegerColumnValue";
} else if (type.equals(JAVA_STRING)) {
    valueType = "StringColumnValue";
...
ConnectiongetConnection(String jdbcUrl, Properties properties)
Get the Connection for the given jdbcUrl.
String driver = jdbcUrl.split(":")[1];
String driverClassName = getDriverClassName(driver);
Class.forName(driverClassName);
return DriverManager.getConnection(jdbcUrl, properties);
intgetDbDataType(Object o)
get Db Data Type
int result = java.sql.Types.VARCHAR;
if (o.getClass().equals(Array.class)) {
    result = java.sql.Types.ARRAY;
} else if (o.getClass().equals(Long.class)) {
    result = java.sql.Types.BIGINT;
} else if (o.getClass().equals(Boolean.class)) {
    result = java.sql.Types.BIT;
} else if (o.getClass().equals(Blob.class)) {
...
intgetDefaultPrecision(int sqlType)
get Default Precision
switch (sqlType) {
case Types.BIGINT:
    return 10;
case Types.BINARY:
    return 1;
case Types.BIT:
    return 1;
case Types.BLOB:
...
intgetDefaultScale(int sqlType)
get Default Scale
switch (sqlType) {
case Types.TIME:
case Types.TIMESTAMP:
    return 3;
case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
case Types.NUMERIC:
...
TgetDefaultValue(Class type)
Get the default value for for a type if one is available OR null if there is no default (since null sorta is the default)
T val = null;
if (getPrimitiveDefaults().containsKey(type)) {
    val = (T) getPrimitiveDefaults().get(type);
} else if (getImmutableDefaults().containsKey(type)) {
    val = (T) getImmutableDefaults().get(type);
return val;
StringgetDoubleTypeString(Connection conn)
get Double Type String
String dbms = "";
try {
    dbms = conn.getMetaData().getDatabaseProductName();
} catch (Exception e) {
    throw new RuntimeException(e);
if (SQLSERVER.equalsIgnoreCase(dbms))
    return "FLOAT"; 
...