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

intgetSQLTypePrecision(int sqlType)
get SQL Type Precision
int resultType = 10; 
switch (sqlType) {
case java.sql.Types.BIT: {
    resultType = 1;
case java.sql.Types.BIGINT: {
    resultType = 19;
    break;
...
intgetSQLTypeRadix(int sqlType)
get SQL Type Radix
int result = -1; 
switch (sqlType) {
case java.sql.Types.REAL:
case java.sql.Types.DOUBLE: {
    result = 10;
    break;
default:
...
StringgetSqlValue(Object o)
get Sql Value
String rtn = null;
if (o == null) {
    rtn = null;
} else {
    if (o instanceof String) {
        rtn = (String) o;
    } else if (o instanceof Number || o instanceof BigDecimal || o instanceof StringBuffer) {
        rtn = o.toString();
...
StringgetStringFormat(int colType)
get String Format
switch (colType) {
case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
    return "%f";
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
...
ListgetTableTypes(DatabaseMetaData dbmd)
get Table Types
final List<String> tableTypes = new LinkedList<String>();
final ResultSet rs = dbmd.getTableTypes();
while (rs.next()) {
    tableTypes.add(rs.getString(1));
rs.close();
return tableTypes;
StringgetTinyIntTypeString(Connection conn)
get Tiny Int Type String
String dbms = getDbmsFromConnection(conn);
if (dbms.equals(ORACLE))
    return "NUMBER(1,0)";
if (dbms.equals(POSTGRESQL))
    return "SMALLINT";
return "TINYINT";
intgetType(int csqltype)
get Type
switch (csqltype) {
case 0:
    return Types.INTEGER;
case 1:
    return Types.BIGINT;
case 2:
    return Types.BIGINT;
case 3:
...
StringgetTypeforValue(int type)
Gets the Field name corresponding to the given type value.
try {
    Class c = Types.class;
    Field[] fields = c.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        String name = fields[i].getName();
        int value = fields[i].getInt(null);
        if (value == type) {
            return name;
...
StringgetTypeName(int dataType)
Given an int datatype, return the java.sql.Types name for that datatype.
switch (dataType) {
case Types.BIGINT:
    return "BIGINT";
case Types.BINARY:
    return "BINARY";
case Types.BIT:
    return "BIT";
case Types.CHAR:
...
StringgetTypeName(int typeNumber)
returns the type names based on the type from java.sql.Types
switch (typeNumber) {
case Types.SMALLINT:
    return "SMALLINT";
case Types.INTEGER:
    return "INTEGER";
case Types.BIGINT:
    return "BIGINT";
case Types.FLOAT:
...