Java SQL Type getSQLType(String text)

Here you can find the source of getSQLType(String text)

Description

Returns the SQL TYPE for a string for example if text is "VARCHAR" java.sql.Types.VARCHAR is returned

License

Open Source License

Parameter

Parameter Description
text a parameter

Return

a static constant of java.sql.Types or NULL if this constant does not exist

Declaration

public static Integer getSQLType(String text) 

Method Source Code

//package com.java2s;

public class Main {
    private static String types = "java.sql.Types.";

    /**//from  w  w w .jav  a2  s. co m
     * Returns the SQL TYPE for a string for example if text is "VARCHAR"
     * java.sql.Types.VARCHAR is returned
     * 
     * @param text
     * @return a static constant of java.sql.Types or NULL if this constant does
     *         not exist
     */
    public static Integer getSQLType(String text) {

        // if full path is given: reduce to type name
        if (text.contains(".") && text.substring(0, types.length()).equalsIgnoreCase(types)) {
            text = text.substring(types.length(), text.length());
        }

        // check needed for case: path was not "java.sql.types"
        if (!text.contains(".")) {
            try {
                java.lang.reflect.Field f = java.sql.Types.class.getField(text);
                return f.getInt(f);
            } catch (IllegalArgumentException e) {
                // only return null;
            } catch (IllegalAccessException e) {
                // only return null;
            } catch (SecurityException e) {
                // only return null;
            } catch (NoSuchFieldException e) {
                // only return null;
            }
        }
        return null;
    }
}

Related

  1. getSQLException(String message, String sqlState, Exception exception)
  2. getSQLParameterSubstring(String value, int type)
  3. getSqlType(int type)
  4. getSqlType(Object param)
  5. getSqlType(String cubridType)
  6. getSQLType(String type)
  7. getSqlTypeAsString(int jdbcType)
  8. getSQLTypeByName(String type)
  9. getSqlTypeByValue(Object value)