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

ObjectconvertBoolean(Object value, int srcType, int destType)
convert Boolean
if ((isNumeric(destType) == true) || ((isString(destType) == false) && (isBoolean(destType) == false))) {
    throw new Exception("boolean conversion failed. (" + value.toString().trim() + "/" + srcType + ":"
            + destType + ")");
try {
    switch (destType) {
    case java.sql.Types.BIT:
        Integer i = new Integer(value.toString().trim());
...
TconvertKnownType(Object one, Class to)
convert Known Type
if (to.isPrimitive()) {
    to = Primitives.wrap(to);
if (one == null) {
    return null;
} else if (Number.class.isAssignableFrom(to)) {
    try {
        return to.getConstructor(String.class).newInstance(one.toString());
...
ObjectconvertNumeric(Object value, int srcType, int destType)
convert Numeric
if (isNumeric(destType) == false && isString(destType) == false) {
    throw new Exception("numeric conversion failed. (" + value.toString().trim() + "/" + srcType + ":"
            + destType + ")");
try {
    switch (destType) {
    case java.sql.Types.BIT:
        Integer i = new Integer(value.toString().trim());
...
ObjectconvertOracleValue(Object value, int type)
convert Oracle Value
String s = value.toString();
if (type == Types.NUMERIC) {
    if (s.contains(".")) {
        return Double.valueOf(s);
    if (s.length() > 11) {
        return Long.valueOf(s);
    if (s.length() <= 11) {
        return Integer.valueOf(s);
if (type == Types.CHAR) {
    if (s.equals("1")) {
        return Boolean.TRUE;
    } else {
        return Boolean.FALSE;
return value;
ObjectconvertParam(Object oValue, Class cType, String sFieldName)
convert Param
String sTypeName = cType.getName();
log("convertParam : type name = '" + sTypeName + "'");
if (oValue == null) {
    if (cType.isPrimitive()) {
        throw new RuntimeException("Cannot set null value : primitive type '" + sTypeName + "'");
    } else {
        return null; 
if (oValue instanceof String) {
    if ("java.lang.String".equals(sTypeName)) {
        return oValue; 
    throw new RuntimeException("Cannot set string in field '" + sFieldName + "' ");
if (oValue instanceof Boolean) {
    if ("java.lang.Boolean".equals(sTypeName) || "boolean".equals(sTypeName)) {
        return oValue; 
    throw new RuntimeException("Cannot set boolean in field '" + sFieldName + "' ");
if (oValue instanceof java.util.Date) {
    java.util.Date date = (java.util.Date) oValue;
    if ("java.util.Date".equals(sTypeName)) {
        return date; 
    if ("java.sql.Date".equals(sTypeName)) {
        return new java.sql.Date(date.getTime());
    if ("java.sql.Time".equals(sTypeName)) {
        return new java.sql.Time(date.getTime());
    if ("java.sql.Timestamp".equals(sTypeName)) {
        return new java.sql.Timestamp(date.getTime());
    throw new RuntimeException("Cannot set date in field '" + sFieldName + "' ");
if (oValue instanceof Number) 
    Number number = (Number) oValue;
    if ("int".equals(sTypeName) || "java.lang.Integer".equals(sTypeName)) {
        return new Integer(number.intValue());
    if ("long".equals(sTypeName) || "java.lang.Long".equals(sTypeName)) {
        return new Long(number.longValue());
    if ("short".equals(sTypeName) || "java.lang.Short".equals(sTypeName)) {
        return new Short(number.shortValue());
    if ("byte".equals(sTypeName) || "java.lang.Byte".equals(sTypeName)) {
        return new Byte(number.byteValue());
    if ("float".equals(sTypeName) || "java.lang.Float".equals(sTypeName)) {
        return new Float(number.floatValue());
    if ("double".equals(sTypeName) || "java.lang.Double".equals(sTypeName)) {
        return new Double(number.doubleValue());
    throw new RuntimeException("Cannot set number in field '" + sFieldName + "' ");
if (oValue instanceof LinkedList) 
    LinkedList<?> list = (LinkedList<?>) oValue;
    if ("java.util.List".equals(sTypeName)) {
        return list; 
    if ("java.util.Collection".equals(sTypeName)) {
        return list; 
    if ("java.util.LinkedList".equals(sTypeName)) {
        return list; 
    if (cType.isArray()) {
        throw new RuntimeException("Array type " + sTypeName + " not yet supported");
return oValue; 
StringconvertSQLtype2JavaClassName(int type)
Translates a data type from an integer (java.sql.Types value) to a string that represents the corresponding class.
if (mapSQLtypeCodeToJavaClass.containsKey(type))
    return mapSQLtypeCodeToJavaClass.get(type);
else
    return JAVA_OBJECT_TYPE_NAME;
intconvertStringToType(String type)
convert String To Type
if (type.equalsIgnoreCase("INTEGER"))
    return Types.INTEGER;
else if (type.equalsIgnoreCase("CHAR"))
    return Types.CHAR;
else if (type.equalsIgnoreCase("VARCHAR"))
    return Types.VARCHAR;
else if (type.equalsIgnoreCase("DATE"))
    return Types.DATE;
...
ObjectconvertTemporal(Object value, int srcType, int destType)
convert Temporal
if (isNumeric(destType) == false && isString(destType) == false) {
    throw new Exception("temporal conversion failed. (" + value.toString().trim() + "/" + srcType + ":"
            + destType + ")");
try {
    switch (destType) {
    case java.sql.Types.DATE:
        if (srcType == java.sql.Types.TIMESTAMP) {
...
intconvertToJDBCType(String talendType)
convert To JDBC Type
Integer type = getTalendDBMap().get(talendType.trim());
return null == type ? 0 : type;
ObjectconvertToProperty(Object value)
convert To Property
if (value != null) {
    if (Date.class.isAssignableFrom(value.getClass())) {
        return dateToLong((Date) value);
    } else if (Enum.class.isAssignableFrom(value.getClass())) {
        return ((Enum<?>) value).name();
    } else if (value instanceof Map) {
        Map map = (Map) value;
        if (map.isEmpty()) { 
...