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

voidaddParameter(PreparedStatement smt, int index, Object value)
Add a paramenter (object) in the index position to an prepared stament
if (value instanceof String) {
    smt.setString(index, value + "");
} else if (value instanceof Integer) {
    smt.setInt(index, (Integer) value);
} else if (value instanceof Double) {
    smt.setDouble(index, (Double) value);
} else if (value instanceof Float) {
    smt.setFloat(index, (Float) value);
...
StringadjustLevel(String attribute, int type)
adjust Level
return adjustLevel(attribute, type, "\"", false);
CallableStatementcallPro2(String sql, String[] inparameters, Integer[] outparameters)
call Pro
try {
    ct = getConnection();
    cs = ct.prepareCall(sql);
    if (inparameters != null) {
        for (int i = 0; i < inparameters.length; i++) {
            cs.setObject(i + 1, inparameters[i]);
    if (outparameters != null) {
        for (int i = 0; i < outparameters.length; i++) {
            cs.registerOutParameter(inparameters.length + 1 + i, outparameters[i]);
    cs.execute();
} catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e.getMessage());
} finally {
return cs;
StringcolumnClassName(int columnType)
column Class Name
switch (columnType) {
case Types.BOOLEAN:
    return Boolean.class.getName();
case Types.CHAR:
case Types.VARCHAR:
    return String.class.getName();
case Types.TINYINT:
    return Byte.class.getName();
...
intcolumnDisplaySize(int columnType)
Column display size.
switch (columnType) {
case Types.BOOLEAN:
    return columnPrecision(columnType);
case Types.CHAR:
case Types.VARCHAR:
    return columnPrecision(columnType);
case Types.BINARY:
    return Integer.MAX_VALUE; 
...
intcolumnPrecision(int columnType)
Column precision.
switch (columnType) {
case Types.BOOLEAN:
    return 1;
case Types.CHAR:
case Types.VARCHAR:
    return Integer.MAX_VALUE; 
case Types.BINARY:
    return Integer.MAX_VALUE; 
...
intcolumnScale(int columnType)
column Scale
switch (columnType) {
case Types.BOOLEAN:
case Types.CHAR:
case Types.VARCHAR:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
...
booleancolumnTypesDiffer(int t1, int t2)
Checks if the given column types materially differ.
int sourceType = compressType(t1);
int targetType = compressType(t2);
return sourceType != targetType;
intcompressType(int type)
Compresses all the different kinds of essentially identical types into an arbitrarily chosen one of them.
if (type == Types.DECIMAL) {
    return Types.NUMERIC;
} else {
    return type;
Stringconvert2MysqlType(String cls)
convert Mysql Type
if (cls.equals("java.lang.String")) {
    return "VARCHAR(20)";
} else if (cls.equals("java.lang.byte[]")) {
    return "BLOB";
} else if (cls.equals("java.lang.Integer") || cls.equals("int")) {
    return "INT";
} else if (cls.equals("java.lang.Long") || cls.equals("long")) {
    return "BIGINT";
...