Example usage for java.sql Types NUMERIC

List of usage examples for java.sql Types NUMERIC

Introduction

In this page you can find the example usage for java.sql Types NUMERIC.

Prototype

int NUMERIC

To view the source code for java.sql Types NUMERIC.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC.

Usage

From source file:org.sakaiproject.warehouse.util.db.DbLoader.java

protected int getJavaSqlType(String genericDataTypeName) {
    // Find the type code for this generic type name
    int dataTypeCode = 0;

    if (genericDataTypeName.equalsIgnoreCase("BIT"))
        dataTypeCode = Types.BIT; // -7
    else if (genericDataTypeName.equalsIgnoreCase("TINYINT"))
        dataTypeCode = Types.TINYINT; // -6
    else if (genericDataTypeName.equalsIgnoreCase("SMALLINT"))
        dataTypeCode = Types.SMALLINT; // 5
    else if (genericDataTypeName.equalsIgnoreCase("INTEGER"))
        dataTypeCode = Types.INTEGER; // 4
    else if (genericDataTypeName.equalsIgnoreCase("BIGINT"))
        dataTypeCode = Types.BIGINT; // -5
    else if (genericDataTypeName.equalsIgnoreCase("FLOAT"))
        dataTypeCode = Types.FLOAT; // 6
    else if (genericDataTypeName.equalsIgnoreCase("REAL"))
        dataTypeCode = Types.REAL; // 7
    else if (genericDataTypeName.equalsIgnoreCase("DOUBLE"))
        dataTypeCode = Types.DOUBLE; // 8
    else if (genericDataTypeName.equalsIgnoreCase("NUMERIC"))
        dataTypeCode = Types.NUMERIC; // 2
    else if (genericDataTypeName.equalsIgnoreCase("DECIMAL"))
        dataTypeCode = Types.DECIMAL; // 3

    else if (genericDataTypeName.equalsIgnoreCase("CHAR"))
        dataTypeCode = Types.CHAR; // 1
    else if (genericDataTypeName.equalsIgnoreCase("VARCHAR"))
        dataTypeCode = Types.VARCHAR; // 12
    else if (genericDataTypeName.equalsIgnoreCase("LONGVARCHAR"))
        dataTypeCode = Types.LONGVARCHAR; // -1

    else if (genericDataTypeName.equalsIgnoreCase("DATE"))
        dataTypeCode = Types.DATE; // 91
    else if (genericDataTypeName.equalsIgnoreCase("TIME"))
        dataTypeCode = Types.TIME; // 92
    else if (genericDataTypeName.equalsIgnoreCase("TIMESTAMP"))
        dataTypeCode = Types.TIMESTAMP; // 93

    else if (genericDataTypeName.equalsIgnoreCase("BINARY"))
        dataTypeCode = Types.BINARY; // -2
    else if (genericDataTypeName.equalsIgnoreCase("VARBINARY"))
        dataTypeCode = Types.VARBINARY; // -3
    else if (genericDataTypeName.equalsIgnoreCase("LONGVARBINARY"))
        dataTypeCode = Types.LONGVARBINARY; // -4

    else if (genericDataTypeName.equalsIgnoreCase("NULL"))
        dataTypeCode = Types.NULL; // 0

    else if (genericDataTypeName.equalsIgnoreCase("OTHER"))
        dataTypeCode = Types.OTHER; // 1111

    else if (genericDataTypeName.equalsIgnoreCase("JAVA_OBJECT"))
        dataTypeCode = Types.JAVA_OBJECT; // 2000
    else if (genericDataTypeName.equalsIgnoreCase("DISTINCT"))
        dataTypeCode = Types.DISTINCT; // 2001
    else if (genericDataTypeName.equalsIgnoreCase("STRUCT"))
        dataTypeCode = Types.STRUCT; // 2002

    else if (genericDataTypeName.equalsIgnoreCase("ARRAY"))
        dataTypeCode = Types.ARRAY; // 2003
    else if (genericDataTypeName.equalsIgnoreCase("BLOB"))
        dataTypeCode = Types.BLOB; // 2004
    else if (genericDataTypeName.equalsIgnoreCase("CLOB"))
        dataTypeCode = Types.CLOB; // 2005
    else if (genericDataTypeName.equalsIgnoreCase("REF"))
        dataTypeCode = Types.REF; // 2006

    return dataTypeCode;
}

From source file:org.executequery.gui.resultset.ResultSetTableModel.java

public Class<?> getColumnClass(int column) {

    if (tableData.isEmpty()) {

        return String.class;
    }//from   w  ww .j a  va2s.  co  m

    RecordDataItem recordDataItem = tableData.get(0).get(column);
    if (recordDataItem.isValueNull()) {

        return String.class;
    }

    int columnType = recordDataItem.getDataType();
    switch (columnType) {

    case Types.TINYINT:
        return Byte.class;

    case Types.BIGINT:
        return Long.class;

    case Types.SMALLINT:
        return Short.class;

    case Types.BIT:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.BOOLEAN: // don't display the checkbox
        return String.class;

    case Types.NUMERIC:
    case Types.DECIMAL:
        return BigDecimal.class;

    case Types.INTEGER:
        return Integer.class;

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return java.util.Date.class;

    case Types.REAL:
        return Float.class;

    case Types.FLOAT:
    case Types.DOUBLE:
        return Double.class;

    default:
        return Object.class;

    }

}

From source file:org.apache.openjpa.jdbc.schema.Column.java

/**
 * Return true if this column is compatible with the given JDBC type
 * from {@link Types} and size.//from  w  w  w. j  av  a 2 s.  co m
 */
public boolean isCompatible(int type, String typeName, int size, int decimals) {
    if (type == Types.OTHER || getType() == Types.OTHER)
        return true;

    // note that the given size is currently ignored, but may be useful
    // to dynamically-populating subclasses
    switch (getType()) {
    case Types.BIT:
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.NUMERIC:
    case Types.SMALLINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
        switch (type) {
        case Types.BIT:
        case Types.TINYINT:
        case Types.BIGINT:
        case Types.INTEGER:
        case Types.NUMERIC:
        case Types.SMALLINT:
        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.FLOAT:
        case Types.REAL:
            return true;
        default:
            return false;
        }
    case Types.BINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.OTHER:
        switch (type) {
        case Types.BINARY:
        case Types.BLOB:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
        case Types.OTHER:
            return true;
        default:
            return false;
        }
    case Types.CLOB:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        switch (type) {
        case Types.CLOB:
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            return true;
        default:
            return false;
        }
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        switch (type) {
        case Types.LONGVARCHAR:
        case Types.CLOB:
        case Types.VARCHAR:
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            return true;
        default:
            return false;
        }
    case 2007: // Oracle-defined opaque type code for XMLType
        switch (type) {
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.CLOB:
        case Types.BLOB:
            return true;
        default:
            return false;
        }

    default:
        return type == getType();
    }
}

From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java

private void updatePageBody(Page page, int prevVersionId) {
    long bodyId = -1L;

    try {//w  w  w  .j av a2 s.  c  om
        bodyId = getExtendedJdbcTemplate().queryForObject(
                getBoundSql("ARCHITECTURE_COMMUNITY.SELETE_PAGE_BODY_ID").getSql(), Long.class,
                new SqlParameterValue(Types.NUMERIC, page.getPageId()),
                new SqlParameterValue(Types.NUMERIC, prevVersionId));
    } catch (EmptyResultDataAccessException e) {
    }
    if (page.getBodyText() != null) {
        if (bodyId != -1L) {
            final long bodyIdToUse = bodyId;
            getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_PAGE_BODY").getSql(),
                    new SqlParameterValue(Types.INTEGER, page.getBodyContent().getBodyType().getId()),
                    new SqlParameterValue(Types.VARCHAR, page.getBodyContent().getBodyText()),
                    new SqlParameterValue(Types.NUMERIC, bodyIdToUse));
        } else {
            final long bodyIdToUse = getNextId("PAGE_BODY");
            getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PAGE_BODY").getSql(),
                    new SqlParameterValue(Types.NUMERIC, bodyIdToUse),
                    new SqlParameterValue(Types.NUMERIC, page.getPageId()),
                    new SqlParameterValue(Types.INTEGER, page.getBodyContent().getBodyType().getId()),
                    new SqlParameterValue(Types.VARCHAR, page.getBodyContent().getBodyText()));
            getExtendedJdbcTemplate().update(
                    getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PAGE_BODY_VERSION").getSql(),
                    new SqlParameterValue(Types.NUMERIC, bodyId),
                    new SqlParameterValue(Types.NUMERIC, page.getPageId()),
                    new SqlParameterValue(Types.NUMERIC, prevVersionId));
        }
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * This tests that copying and pasting a table with source information into
 * the play pen works. This also confirms that the new table copied has the
 * same sources as the original table and does not use the table copied from
 * as its source. Note that this is testing copy, not reverse engineering.
 *///  w  w  w.ja v  a  2 s .  c o  m
public void testPasteCopyTable() throws Exception {
    SQLDatabase db = new SQLDatabase();
    pp.getSession().getRootObject().addChild(db);
    SQLColumn sourceCol = new SQLColumn();
    SQLTable sourceTable = new SQLTable(db, true);
    sourceTable.addColumn(sourceCol);
    SQLTable table = new SQLTable(db, "NewTable", "Remarks", "TABLE", true);
    final SQLColumn col1 = new SQLColumn(table, "NewCol1", Types.VARCHAR, 50, 0);
    col1.setSourceColumn(sourceCol);
    table.addColumn(col1);
    final SQLColumn col2 = new SQLColumn(table, "NewCol2", Types.NUMERIC, 50, 0);
    col2.setSourceColumn(sourceCol);
    table.addColumn(col2);

    DuplicateProperties duplicateProperties = ASUtils.createDuplicateProperties(pp.getSession(), table);
    duplicateProperties.setDefaultTransferStyle(TransferStyles.COPY);
    pp.importTableCopy(table, new Point(0, 0), duplicateProperties);
    assertEquals(1, pp.getTables().size());
    SQLTable copy = pp.getTables().get(0);
    assertEquals("NewTable", copy.getName());
    assertEquals(2, copy.getColumns().size());
    assertTrue(copy.getColumnByName("NewCol1") != null);
    assertTrue(copy.getColumnByName("NewCol2") != null);
    assertEquals(sourceCol, copy.getColumnByName("NewCol1").getSourceColumn());
    assertEquals(sourceCol, copy.getColumnByName("NewCol2").getSourceColumn());
}

From source file:org.apache.torque.engine.database.model.TypeMap.java

/**
 * Initializes the SQL to Java map so that it
 * can be used by client code.// w  w w . j  a  v  a 2s.com
 */
public static synchronized void initialize() {
    if (!isInitialized) {
        // Create JDBC -> Java object mappings.
        jdbcToJavaObjectMap = new Hashtable();

        jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE);

        // Create JDBC -> native Java type mappings.
        jdbcToJavaNativeMap = new Hashtable();

        jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE);

        jdbcToJavaNativeObjectMap = new Hashtable();
        jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_OBJECT_TYPE);

        // Create JDBC -> Village asX() mappings.
        jdbcToVillageMethodMap = new Hashtable();

        jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD);

        jdbcToVillageObjectMethodMap = new Hashtable();
        jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_OBJECT_METHOD);

        // Create JDBC -> ParameterParser getX() mappings.
        jdbcToPPMethodMap = new Hashtable();

        jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD);

        // Create JDBC -> Java object mappings.
        torqueTypeToJdbcTypeMap = new Hashtable();

        Iterator iter = SchemaType.iterator();
        while (iter.hasNext()) {
            SchemaType type = (SchemaType) iter.next();
            torqueTypeToJdbcTypeMap.put(type, type);
        }
        torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR);
        torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER);

        // Create JDBC type code to torque type map.
        jdbcToTorqueTypeMap = new Hashtable();

        jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB);
        jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC);
        jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL);
        jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT);
        jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER);
        jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL);
        jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT);
        jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE);
        jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB);
        jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE);
        jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME);
        jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP);

        isInitialized = true;
    }
}

From source file:org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereTriggerTemplate.java

@Override
protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
    String text = "";
    for (int i = 0; i < columns.length; i++) {
        text += "declare @" + prefix + "pk" + i + " ";
        switch (columns[i].getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            text += "bigint\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            text += "decimal\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case ColumnTypes.NVARCHAR:
        case ColumnTypes.LONGNVARCHAR:
        case Types.LONGVARCHAR:
            text += "varchar(1000)\n";
            break;
        case Types.DATE:
            text += "date\n";
            break;
        case Types.TIME:
            text += "time\n";
            break;
        case Types.TIMESTAMP:
            text += "datetime\n";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            text += "bit\n";
            break;
        case Types.CLOB:
            text += "varchar(16384)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(16384)\n";
            break;
        case Types.OTHER:
            text += "varbinary(16384)\n";
            break;
        default:/*from  w w w. j  a va  2  s  .  co  m*/
            if (columns[i].getJdbcTypeName() != null
                    && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
                text += "interval";
                break;
            }
            throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType());
        }
    }

    return text;
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize,
        int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction,
        boolean timestampToString) throws SQLException, IOException, StageException {
    Field field;//from   w  w w  . j  av a  2s .  co m
    if (userSpecifiedType != DataType.USE_COLUMN_TYPE) {
        // If user specifies the data type, overwrite the column type returned by database.
        field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex));
    } else {
        // All types as of JDBC 2.0 are here:
        // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY
        // Good source of recommended mappings is here:
        // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html
        switch (md.getColumnType(columnIndex)) {
        case Types.BIGINT:
            field = Field.create(Field.Type.LONG, rs.getObject(columnIndex));
            break;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
            field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex));
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex));
            break;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            field = Field.create(Field.Type.STRING, rs.getObject(columnIndex));
            break;
        case Types.CLOB:
        case Types.NCLOB:
            field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize));
            break;
        case Types.BLOB:
            field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize));
            break;
        case Types.DATE:
            field = Field.create(Field.Type.DATE, rs.getDate(columnIndex));
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex));
            field.setAttribute(HeaderAttributeConstants.ATTR_SCALE,
                    String.valueOf(rs.getMetaData().getScale(columnIndex)));
            field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION,
                    String.valueOf(rs.getMetaData().getPrecision(columnIndex)));
            break;
        case Types.DOUBLE:
            field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex));
            break;
        case Types.FLOAT:
        case Types.REAL:
            field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex));
            break;
        case Types.INTEGER:
            field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex));
            break;
        case Types.ROWID:
            field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString());
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex));
            break;
        case Types.TIME:
            field = Field.create(Field.Type.TIME, rs.getObject(columnIndex));
            break;
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnIndex);
            if (timestampToString) {
                field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString());
            } else {
                field = Field.create(Field.Type.DATETIME, timestamp);
                if (timestamp != null) {
                    final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT;
                    if (actualNanos > 0) {
                        field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos));
                    }
                }
            }
            break;
        // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc.
        case Types.TIME_WITH_TIMEZONE:
            OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class);
            field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant()));
            break;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class);
            field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime());
            break;
        //case Types.REF_CURSOR: // JDK8 only
        case Types.SQLXML:
        case Types.STRUCT:
        case Types.ARRAY:
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.NULL:
        case Types.OTHER:
        case Types.REF:
        default:
            if (unknownTypeAction == null) {
                return null;
            }
            switch (unknownTypeAction) {
            case STOP_PIPELINE:
                throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex),
                        md.getColumnLabel(columnIndex));
            case CONVERT_TO_STRING:
                Object value = rs.getObject(columnIndex);
                if (value != null) {
                    field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString());
                } else {
                    field = Field.create(Field.Type.STRING, null);
                }
                break;
            default:
                throw new IllegalStateException("Unknown action: " + unknownTypeAction);
            }
        }
    }

    return field;
}

From source file:org.springframework.jdbc.core.JdbcTemplateTests.java

/**
 * Test update with dynamic SQL./*from  w ww  .  j av a 2  s  . co  m*/
 */
public void testSqlUpdateWithArguments() throws Exception {
    final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ? and PR = ?";
    int rowsAffected = 33;

    MockControl ctrlStatement = MockControl.createControl(PreparedStatement.class);
    PreparedStatement mockStatement = (PreparedStatement) ctrlStatement.getMock();
    mockStatement.setObject(1, new Integer(4));
    ctrlStatement.setVoidCallable();
    mockStatement.setObject(2, new Float(1.4142), Types.NUMERIC, 2);
    ctrlStatement.setVoidCallable();
    mockStatement.executeUpdate();
    ctrlStatement.setReturnValue(33);
    if (debugEnabled) {
        mockStatement.getWarnings();
        ctrlStatement.setReturnValue(null);
    }
    mockStatement.close();
    ctrlStatement.setVoidCallable();

    mockConnection.prepareStatement(sql);
    ctrlConnection.setReturnValue(mockStatement);
    ctrlStatement.replay();
    replay();

    JdbcTemplate template = new JdbcTemplate(mockDataSource);
    int actualRowsAffected = template.update(sql,
            new Object[] { new Integer(4), new SqlParameterValue(Types.NUMERIC, 2, new Float(1.4142)) });
    assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
    ctrlStatement.verify();
}

From source file:org.infoglue.cms.util.workflow.InfoGlueJDBCPropertySet.java

private void setValues(PreparedStatement ps, int type, String key, Object value)
        throws SQLException, PropertyException {
    // Patched by Edson Richter for MS SQL Server JDBC Support!
    String driverName;/*w  w  w .  j  a va2 s .  co m*/

    try {
        driverName = ps.getConnection().getMetaData().getDriverName().toUpperCase();
    } catch (Exception e) {
        driverName = "";
    }

    ps.setNull(1, Types.VARCHAR);
    ps.setNull(2, Types.TIMESTAMP);

    // Patched by Edson Richter for MS SQL Server JDBC Support!
    // Oracle support suggestion also Michael G. Slack
    if ((driverName.indexOf("SQLSERVER") >= 0) || (driverName.indexOf("ORACLE") >= 0)) {
        ps.setNull(3, Types.BINARY);
    } else {
        ps.setNull(3, Types.BLOB);
    }

    ps.setNull(4, Types.FLOAT);
    ps.setNull(5, Types.NUMERIC);
    ps.setInt(6, type);
    ps.setString(7, globalKey);
    ps.setString(8, key);

    switch (type) {
    case PropertySet.BOOLEAN:

        Boolean boolVal = (Boolean) value;
        ps.setInt(5, boolVal.booleanValue() ? 1 : 0);

        break;

    case PropertySet.DATA:

        Data data = (Data) value;
        ps.setBytes(3, data.getBytes());

        break;

    case PropertySet.DATE:

        Date date = (Date) value;
        ps.setTimestamp(2, new Timestamp(date.getTime()));

        break;

    case PropertySet.DOUBLE:

        Double d = (Double) value;
        ps.setDouble(4, d.doubleValue());

        break;

    case PropertySet.INT:

        Integer i = (Integer) value;
        ps.setInt(5, i.intValue());

        break;

    case PropertySet.LONG:

        Long l = (Long) value;
        ps.setLong(5, l.longValue());

        break;

    case PropertySet.STRING:
        ps.setString(1, (String) value);

        break;

    default:
        throw new PropertyException("This type isn't supported!");
    }

    if (valueMap == null)
        valueMap = new HashMap();
    if (typeMap == null)
        typeMap = new HashMap();

    valueMap.put(key, value);
    typeMap.put(key, new Integer(type));
}