Example usage for java.sql Types TIME

List of usage examples for java.sql Types TIME

Introduction

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

Prototype

int TIME

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

Click Source Link

Document

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

Usage

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Retrieve the fully qualified java class name for the
 * supplied JDBC Types constant.//from  ww w.  java 2 s  . c  o m
 *
 * @param jdbcType The JDBC Types constant.
 * @return The fully qualified java class name as a <code>String</code>.
 */
static String getClassName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.BOOLEAN:
    case java.sql.Types.BIT:
        return "java.lang.Boolean";

    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
        return "java.lang.Integer";

    case java.sql.Types.BIGINT:
        return "java.lang.Long";

    case java.sql.Types.NUMERIC:
    case java.sql.Types.DECIMAL:
        return "java.math.BigDecimal";

    case java.sql.Types.REAL:
        return "java.lang.Float";

    case java.sql.Types.FLOAT:
    case java.sql.Types.DOUBLE:
        return "java.lang.Double";

    case java.sql.Types.CHAR:
    case java.sql.Types.VARCHAR:
        return "java.lang.String";

    case java.sql.Types.BINARY:
    case java.sql.Types.VARBINARY:
        return "[B";

    case java.sql.Types.LONGVARBINARY:
    case java.sql.Types.BLOB:
        return "java.sql.Blob";

    case java.sql.Types.LONGVARCHAR:
    case java.sql.Types.CLOB:
        return "java.sql.Clob";

    case java.sql.Types.DATE:
        return "java.sql.Date";

    case java.sql.Types.TIME:
        return "java.sql.Time";

    case java.sql.Types.TIMESTAMP:
        return "java.sql.Timestamp";
    default:
        break;
    }

    return "java.lang.Object";
}

From source file:org.jumpmind.symmetric.db.ase.AseTriggerTemplate.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:
            // ASE does not support bigint
            text += "NUMERIC(18,0)\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            // Use same default scale and precision used by Sybase ASA
            // for a decimal with unspecified scale and precision.
            text += "decimal(30,6)\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        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(32767)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(32767)\n";
            break;
        case Types.OTHER:
            text += "varbinary(32767)\n";
            break;
        default:// w  w  w .ja  va  2  s .  c  o 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:io.bibleget.BibleGetDB.java

private void listColNamesTypes(DatabaseMetaData dbMeta, ResultSet rs) {
    //System.out.println("After Table Creation: Table "+rs.getString("TABLE_NAME")+" exists !!");
    ResultSet cols;/*from  w  ww.  j av a  2 s  .  c  o  m*/
    try {
        cols = dbMeta.getColumns(null, null, rs.getString("TABLE_NAME"), null);
        while (cols.next()) {
            //System.out.println(cols.getString("COLUMN_NAME"));
            colNames.add(cols.getString("COLUMN_NAME"));
            int dType = cols.getInt("DATA_TYPE");
            switch (dType) {
            case Types.VARCHAR:
                colDataTypes.add(String.class);
                break;
            case Types.INTEGER:
                colDataTypes.add(Integer.class);
                break;
            case Types.FLOAT:
                colDataTypes.add(Float.class);
                break;
            case Types.DOUBLE:
            case Types.REAL:
                colDataTypes.add(Double.class);
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                colDataTypes.add(java.sql.Date.class);
                break;
            case Types.BOOLEAN:
                colDataTypes.add(Boolean.class);
                break;
            default:
                colDataTypes.add(String.class);
                break;
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static boolean isPrimitiveType(int colType) {

    switch (colType) {

    case Types.BIT:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return true;

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return false;

    default://  ww  w.jav  a  2s . c om
        return false;
    }
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testObject() throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs;/* w w w . ja  v  a 2  s  .c  o  m*/
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
    stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
    PreparedStatement prep = conn
            .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
    prep.setObject(1, Boolean.TRUE);
    prep.setObject(2, "Abc");
    prep.setObject(3, new BigDecimal("10.2"));
    prep.setObject(4, new Byte((byte) 0xff));
    prep.setObject(5, new Short(Short.MAX_VALUE));
    prep.setObject(6, new Integer(Integer.MIN_VALUE));
    prep.setObject(7, new Long(Long.MAX_VALUE));
    prep.setObject(8, new Float(Float.MAX_VALUE));
    prep.setObject(9, new Double(Double.MAX_VALUE));
    prep.setObject(10, Date.valueOf("2001-02-03"));
    prep.setObject(11, Time.valueOf("04:05:06"));
    prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
    prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime()));
    prep.setObject(14, new byte[] { 10, 20, 30 });
    prep.setObject(15, new Character('a'), Types.OTHER);
    prep.setObject(16, "2001-01-02", Types.DATE);
    // converting to null seems strange...
    prep.setObject(17, "2001-01-02", Types.NULL);
    prep.setObject(18, "3.725", Types.DOUBLE);
    prep.setObject(19, "23:22:21", Types.TIME);
    prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
    rs = prep.executeQuery();
    rs.next();
    assertTrue(rs.getObject(1).equals(Boolean.TRUE));
    assertTrue(rs.getObject(2).equals("Abc"));
    assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
    assertTrue(rs.getObject(4).equals((byte) 0xff));
    assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
    assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
    assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
    assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE)));
    assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE)));
    assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03")));
    assertEquals("04:05:06", rs.getObject(11).toString());
    assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06")));
    assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
    assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00")));
    assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
    assertTrue(rs.getObject(15).equals('a'));
    assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02")));
    assertTrue(rs.getObject(17) == null && rs.wasNull());
    assertTrue(rs.getObject(18).equals(new Double(3.725)));
    assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21")));
    assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345")));

    // } else if(x instanceof java.io.Reader) {
    // return session.createLob(Value.CLOB,
    // TypeConverter.getInputStream((java.io.Reader)x), 0);
    // } else if(x instanceof java.io.InputStream) {
    // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0);
    // } else {
    // return ValueBytes.get(TypeConverter.serialize(x));

    stat.execute("DROP TABLE TEST");

}

From source file:ro.nextreports.engine.queryexec.QueryExecutor.java

private void setParameterValue(PreparedStatement pstmt, Class paramValueClass, Object paramValue, int index)
        throws SQLException, QueryException {

    // for "NOT IN (?)" setting null -> result is undeterminated
    // ParameterUtil.NULL was good only for list of strings (for NOT IN)!
    if (ParameterUtil.NULL.equals(paramValue)) {
        paramValue = null;/*from  w  ww  .java 2 s  .  c o  m*/
    }
    if (paramValueClass.equals(Object.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.JAVA_OBJECT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setObject(index + 1, ((IdName) paramValue).getId());
            } else {
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(Boolean.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setBoolean(index + 1, (Boolean) ((IdName) paramValue).getId());
            } else {
                pstmt.setBoolean(index + 1, (Boolean) paramValue);
            }
        }
    } else if (paramValueClass.equals(Byte.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TINYINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setByte(index + 1, (Byte) ((IdName) paramValue).getId());
            } else {
                pstmt.setByte(index + 1, (Byte) paramValue);
            }
        }
    } else if (paramValueClass.equals(Double.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DOUBLE);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setDouble(index + 1, (Double) ((IdName) paramValue).getId());
            } else {
                pstmt.setDouble(index + 1, (Double) paramValue);
            }
        }
    } else if (paramValueClass.equals(Float.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.FLOAT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setFloat(index + 1, (Float) ((IdName) paramValue).getId());
            } else {
                pstmt.setFloat(index + 1, (Float) paramValue);
            }
        }
    } else if (paramValueClass.equals(Integer.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.INTEGER);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setObject(index + 1, ((IdName) paramValue).getId());
            } else {
                pstmt.setInt(index + 1, (Integer) paramValue);
            }
        }
    } else if (paramValueClass.equals(Long.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIGINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setLong(index + 1, (Long) ((IdName) paramValue).getId());
            } else {
                pstmt.setLong(index + 1, (Long) paramValue);
            }
        }
    } else if (paramValueClass.equals(Short.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.SMALLINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setShort(index + 1, (Short) ((IdName) paramValue).getId());
            } else {
                pstmt.setShort(index + 1, (Short) paramValue);
            }
        }

        //@todo    
        // ParameterUtil -> values are taken from dialect (where there is no BigDecimal yet!)
        // or from meta  data
    } else if (paramValueClass.equals(BigDecimal.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DECIMAL);
        } else {
            if (paramValue instanceof IdName) {
                Serializable ser = ((IdName) paramValue).getId();
                if (ser instanceof BigDecimal) {
                    pstmt.setBigDecimal(index + 1, (BigDecimal) (ser));
                } else {
                    pstmt.setInt(index + 1, (Integer) (ser));
                }
            } else {
                // a simple value cannot be cast to BigDecimal!                   
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(BigInteger.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIGINT);
        } else {
            if (paramValue instanceof IdName) {
                Serializable ser = ((IdName) paramValue).getId();
                if (ser instanceof BigInteger) {
                    pstmt.setBigDecimal(index + 1, new BigDecimal((BigInteger) (ser)));
                } else if (ser instanceof BigDecimal) {
                    pstmt.setBigDecimal(index + 1, (BigDecimal) (ser));
                } else {
                    pstmt.setInt(index + 1, (Integer) (ser));
                }
            } else {
                // a simple value cannot be cast to BigDecimal!                   
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(String.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.VARCHAR);
        } else {
            if (paramValue instanceof IdName) {
                if (((IdName) paramValue).getId() == null) {
                    pstmt.setNull(index + 1, Types.VARCHAR);
                } else {
                    pstmt.setString(index + 1, ((IdName) paramValue).getId().toString());
                }
            } else {
                pstmt.setString(index + 1, paramValue.toString());
            }
        }
    } else if (paramValueClass.equals(Date.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DATE);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }
                pstmt.setDate(index + 1, new java.sql.Date(date.getTime()));
            } else {
                pstmt.setDate(index + 1, new java.sql.Date(((Date) paramValue).getTime()));
            }
        }
    } else if (paramValueClass.equals(Timestamp.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TIMESTAMP);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }

                pstmt.setTimestamp(index + 1, new Timestamp(date.getTime()));
            } else {
                pstmt.setTimestamp(index + 1, new Timestamp(((Date) paramValue).getTime()));
            }
        }
    } else if (paramValueClass.equals(Time.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TIME);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }
                pstmt.setTime(index + 1, new Time(date.getTime()));
            } else {
                pstmt.setTime(index + 1, new Time(((Date) paramValue).getTime()));
            }
        }
    } else {
        throw new QueryException("Parameter type " + paramValueClass.getName() + " not supported in query");
    }

    // for logSql()
    statementParameters.put(index, paramValue);
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.TabularResultLayout.java

private void setEditor(Grid.Column gridColumn, Column tableColumn, List<TextField> primaryKeyEditors) {
    TextField editor = new TextField();
    int typeCode = tableColumn.getMappedTypeCode();

    switch (typeCode) {
    case Types.DATE:
        editor.setConverter(new ObjectConverter(Date.class, typeCode));
        break;/* ww  w . ja  va  2 s.c o m*/
    case Types.TIME:
        editor.setConverter(new ObjectConverter(Time.class, typeCode));
        break;
    case Types.TIMESTAMP:
        editor.setConverter(new ObjectConverter(Timestamp.class, typeCode));
        break;
    case Types.BIT:
        editor.setConverter(new StringToBooleanConverter());
        break;
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
    case Types.INTEGER:
        editor.setConverter(new StringToLongConverter() {
            private static final long serialVersionUID = 1L;

            public NumberFormat getFormat(Locale locale) {
                NumberFormat format = super.getFormat(locale);
                format.setGroupingUsed(false);
                return format;
            }
        });
        break;
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
    case Types.NUMERIC:
    case Types.DECIMAL:
        editor.setConverter(new StringToBigDecimalConverter() {
            private static final long serialVersionUID = 1L;

            public NumberFormat getFormat(Locale locale) {
                NumberFormat format = super.getFormat(locale);
                format.setGroupingUsed(false);
                return format;
            }
        });
        break;
    default:
        break;
    }

    editor.addValidator(new TableChangeValidator(editor, tableColumn));

    editor.setNullRepresentation("");
    if (!tableColumn.isRequired()) {
        editor.setNullSettingAllowed(true);
    }

    if (tableColumn.isPrimaryKey()) {
        primaryKeyEditors.add(editor);
    }

    gridColumn.setEditorField(editor);
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

public boolean setHibernateType(@Nullable SimpleValue value,
        com.manydesigns.portofino.model.database.Column column, Class javaType, final int jdbcType) {
    String typeName;/*from  w ww .  j av  a 2s.com*/
    Properties typeParams = null;
    if (javaType == null) {
        return false;
    }
    if (javaType == Long.class) {
        typeName = LongType.INSTANCE.getName();
    } else if (javaType == Short.class) {
        typeName = ShortType.INSTANCE.getName();
    } else if (javaType == Integer.class) {
        typeName = IntegerType.INSTANCE.getName();
    } else if (javaType == Byte.class) {
        typeName = ByteType.INSTANCE.getName();
    } else if (javaType == Float.class) {
        typeName = FloatType.INSTANCE.getName();
    } else if (javaType == Double.class) {
        typeName = DoubleType.INSTANCE.getName();
    } else if (javaType == Character.class) {
        typeName = CharacterType.INSTANCE.getName();
    } else if (javaType == String.class) {
        typeName = StringType.INSTANCE.getName();
    } else if (java.util.Date.class.isAssignableFrom(javaType)) {
        switch (jdbcType) {
        case Types.DATE:
            typeName = DateType.INSTANCE.getName();
            break;
        case Types.TIME:
            typeName = TimeType.INSTANCE.getName();
            break;
        case Types.TIMESTAMP:
            typeName = TimestampType.INSTANCE.getName();
            break;
        default:
            typeName = null;
        }
    } else if (javaType == Boolean.class) {
        if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) {
            typeName = BooleanType.INSTANCE.getName();
        } else if (jdbcType == Types.NUMERIC || jdbcType == Types.DECIMAL || jdbcType == Types.INTEGER
                || jdbcType == Types.SMALLINT || jdbcType == Types.TINYINT || jdbcType == Types.BIGINT) {
            typeName = NumericBooleanType.INSTANCE.getName();
        } else if (jdbcType == Types.CHAR || jdbcType == Types.VARCHAR) {
            typeName = StringBooleanType.class.getName();
            typeParams = new Properties();
            typeParams.setProperty("true", trueString != null ? trueString : StringBooleanType.NULL);
            typeParams.setProperty("false", falseString != null ? falseString : StringBooleanType.NULL);
            typeParams.setProperty("sqlType", String.valueOf(jdbcType));
        } else {
            typeName = null;
        }
    } else if (javaType == BigDecimal.class) {
        typeName = BigDecimalType.INSTANCE.getName();
    } else if (javaType == BigInteger.class) {
        typeName = BigIntegerType.INSTANCE.getName();
    } else if (javaType == byte[].class) {
        typeName = BlobType.INSTANCE.getName();
    } else {
        typeName = null;
    }

    if (typeName == null) {
        logger.error("Unsupported type (java type: {}, jdbc type: {}) " + "for column '{}'.",
                new Object[] { javaType, jdbcType, column.getColumnName() });
        return false;
    }

    if (value != null) {
        value.setTypeName(typeName);
        if (typeParams != null) {
            value.setTypeParameters(typeParams);
        }
    }
    return true;
}

From source file:org.dspace.storage.rdbms.DatabaseManager.java

/**
 * Convert the current row in a ResultSet into a TableRow object.
 *
 * @param results//from   w ww .  j  av a 2 s. c o  m
 *            A ResultSet to process
 * @param table
 *            The name of the table
 * @param pColumnNames
 *            The name of the columns in this resultset
 * @return A TableRow object with the data from the ResultSet
 * @exception SQLException
 *                If a database error occurs
 */
static TableRow process(ResultSet results, String table, List<String> pColumnNames) throws SQLException {
    ResultSetMetaData meta = results.getMetaData();
    int columns = meta.getColumnCount() + 1;

    // If we haven't been passed the column names try to generate them from the metadata / table
    List<String> columnNames = pColumnNames != null ? pColumnNames
            : ((table == null) ? getColumnNames(meta) : getColumnNames(table));

    TableRow row = new TableRow(canonicalize(table), columnNames);

    // Process the columns in order
    // (This ensures maximum backwards compatibility with
    // old JDBC drivers)
    for (int i = 1; i < columns; i++) {
        String name = meta.getColumnName(i);
        int jdbctype = meta.getColumnType(i);

        switch (jdbctype) {
        case Types.BIT:
            row.setColumn(name, results.getBoolean(i));
            break;

        case Types.INTEGER:
        case Types.NUMERIC:
            if (isOracle) {
                long longValue = results.getLong(i);
                if (longValue <= (long) Integer.MAX_VALUE) {
                    row.setColumn(name, (int) longValue);
                } else {
                    row.setColumn(name, longValue);
                }
            } else {
                row.setColumn(name, results.getInt(i));
            }
            break;

        case Types.DECIMAL:
        case Types.BIGINT:
            row.setColumn(name, results.getLong(i));
            break;

        case Types.DOUBLE:
            row.setColumn(name, results.getDouble(i));
            break;

        case Types.CLOB:
            if (isOracle) {
                row.setColumn(name, results.getString(i));
            } else {
                throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
            }
            break;

        case Types.VARCHAR:
            try {
                byte[] bytes = results.getBytes(i);

                if (bytes != null) {
                    String mystring = new String(results.getBytes(i), "UTF-8");
                    row.setColumn(name, mystring);
                } else {
                    row.setColumn(name, results.getString(i));
                }
            } catch (UnsupportedEncodingException e) {
                log.error("Unable to parse text from database", e);
            }
            break;

        case Types.DATE:
            row.setColumn(name, results.getDate(i));
            break;

        case Types.TIME:
            row.setColumn(name, results.getTime(i));
            break;

        case Types.TIMESTAMP:
            row.setColumn(name, results.getTimestamp(i));
            break;

        default:
            throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
        }

        // Determines if the last column was null, and sets the tablerow accordingly
        if (results.wasNull()) {
            row.setColumnNull(name);
        }
    }

    // Now that we've prepped the TableRow, reset the flags so that we can detect which columns have changed
    row.resetChanged();
    return row;
}

From source file:org.jumpmind.symmetric.db.AbstractTriggerTemplate.java

protected ColumnString fillOutColumnTemplate(String origTableAlias, String tableAlias, String columnPrefix,
        Column column, DataEventType dml, boolean isOld, Channel channel, Trigger trigger) {
    boolean isLob = symmetricDialect.getPlatform().isLob(column.getMappedTypeCode());
    String templateToUse = null;/*ww w  . j a  v a2 s . co m*/
    if (column.getJdbcTypeName() != null && (column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY))
            && StringUtils.isNotBlank(geometryColumnTemplate)) {
        templateToUse = geometryColumnTemplate;
    } else if (column.getJdbcTypeName() != null
            && (column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY))
            && StringUtils.isNotBlank(geographyColumnTemplate)) {
        templateToUse = geographyColumnTemplate;
    } else {
        switch (column.getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
        case Types.DECIMAL:
            templateToUse = numberColumnTemplate;
            break;
        case Types.CHAR:
        case Types.NCHAR:
        case Types.VARCHAR:
        case ColumnTypes.NVARCHAR:
            templateToUse = stringColumnTemplate;
            break;
        case ColumnTypes.SQLXML:
            templateToUse = xmlColumnTemplate;
            break;
        case Types.ARRAY:
            templateToUse = arrayColumnTemplate;
            break;
        case Types.LONGVARCHAR:
        case ColumnTypes.LONGNVARCHAR:
            if (!isLob) {
                templateToUse = stringColumnTemplate;
                break;
            }
        case Types.CLOB:
            if (isOld && symmetricDialect.needsToSelectLobData()) {
                templateToUse = emptyColumnTemplate;
            } else {
                templateToUse = clobColumnTemplate;
            }
            break;
        case Types.BINARY:
        case Types.VARBINARY:
            if (isNotBlank(binaryColumnTemplate)) {
                templateToUse = binaryColumnTemplate;
                break;
            }
        case Types.BLOB:
            if (requiresWrappedBlobTemplateForBlobType()) {
                templateToUse = wrappedBlobColumnTemplate;
                break;
            }
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            if (column.getJdbcTypeName() != null
                    && (column.getJdbcTypeName().toUpperCase().contains(TypeMap.IMAGE))
                    && StringUtils.isNotBlank(imageColumnTemplate)) {
                if (isOld) {
                    templateToUse = emptyColumnTemplate;
                } else {
                    templateToUse = imageColumnTemplate;
                }
            } else if (isOld && symmetricDialect.needsToSelectLobData()) {
                templateToUse = emptyColumnTemplate;
            } else {
                templateToUse = blobColumnTemplate;
            }
            break;
        case Types.DATE:
            if (noDateColumnTemplate()) {
                templateToUse = datetimeColumnTemplate;
                break;
            }
            templateToUse = dateColumnTemplate;
            break;
        case Types.TIME:
            if (noTimeColumnTemplate()) {
                templateToUse = datetimeColumnTemplate;
                break;
            }
            templateToUse = timeColumnTemplate;
            break;
        case Types.TIMESTAMP:
            templateToUse = datetimeColumnTemplate;
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            templateToUse = booleanColumnTemplate;
            break;
        default:
            if (column.getJdbcTypeName() != null) {
                if (column.getJdbcTypeName().toUpperCase().equals(TypeMap.INTERVAL)) {
                    templateToUse = numberColumnTemplate;
                    break;
                } else if (column.getMappedType().equals(TypeMap.TIMESTAMPTZ)
                        && StringUtils.isNotBlank(this.dateTimeWithTimeZoneColumnTemplate)) {
                    templateToUse = this.dateTimeWithTimeZoneColumnTemplate;
                    break;
                } else if (column.getMappedType().equals(TypeMap.TIMESTAMPLTZ)
                        && StringUtils.isNotBlank(this.dateTimeWithLocalTimeZoneColumnTemplate)) {
                    templateToUse = this.dateTimeWithLocalTimeZoneColumnTemplate;
                    break;
                }

            }

            if (StringUtils.isBlank(templateToUse) && StringUtils.isNotBlank(this.otherColumnTemplate)) {
                templateToUse = this.otherColumnTemplate;
                break;
            }

            throw new NotImplementedException(column.getName() + " is of type " + column.getMappedType()
                    + " with JDBC type of " + column.getJdbcTypeName());
        }
    }

    if (dml == DataEventType.DELETE && isLob && requiresEmptyLobTemplateForDeletes()) {
        templateToUse = emptyColumnTemplate;
    } else if (isLob && trigger.isUseStreamLobs()) {
        templateToUse = emptyColumnTemplate;
    }

    if (templateToUse != null) {
        templateToUse = templateToUse.trim();
    } else {
        throw new NotImplementedException();
    }

    String formattedColumnText = FormatUtils.replace("columnName",
            String.format("%s%s", columnPrefix, column.getName()), templateToUse);

    formattedColumnText = FormatUtils.replace("columnSize", column.getSize(), formattedColumnText);

    formattedColumnText = FormatUtils.replace("masterCollation", symmetricDialect.getMasterCollation(),
            formattedColumnText);

    if (isLob) {
        formattedColumnText = symmetricDialect.massageForLob(formattedColumnText, channel);
    }

    formattedColumnText = FormatUtils.replace("origTableAlias", origTableAlias, formattedColumnText);
    formattedColumnText = FormatUtils.replace("tableAlias", tableAlias, formattedColumnText);
    formattedColumnText = FormatUtils.replace("prefixName", symmetricDialect.getTablePrefix(),
            formattedColumnText);

    return new ColumnString(formattedColumnText, isLob);

}