Java Code Examples for java.sql.Types#NUMERIC

The following examples show how to use java.sql.Types#NUMERIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Field.java    From r-course with MIT License 6 votes vote down vote up
private boolean determineNeedsQuoting() {
    boolean retVal = false;

    switch (this.sqlType) {
        case Types.BIGINT:
        case Types.BIT:
        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.FLOAT:
        case Types.INTEGER:
        case Types.NUMERIC:
        case Types.REAL:
        case Types.SMALLINT:
        case Types.TINYINT:
            retVal = false;
            break;
        default:
            retVal = true;
    }
    return retVal;

}
 
Example 2
Source File: ResultSetMetaData.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Is the column a signed number?
 * 
 * @param column
 *            the first column is 1, the second is 2...
 * 
 * @return true if so
 * 
 * @throws SQLException
 *             if a database access error occurs
 */
public boolean isSigned(int column) throws SQLException {
    Field f = getField(column);
    int sqlType = f.getSQLType();

    switch (sqlType) {
        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:
            return !f.isUnsigned();

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            return false;

        default:
            return false;
    }
}
 
Example 3
Source File: JdbcDebugUtil.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
private static Object getColumnValue( ResultSet resultSet, ResultSetMetaData meta, int col ) throws SQLException {
    int type = meta.getColumnType(col);
    switch( type ) {
        case Types.BIT:
                        return new Boolean(resultSet.getBoolean(col));
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
                        return resultSet.getString(col);
        case Types.TINYINT:
        case Types.SMALLINT:
                        return new Short(resultSet.getShort(col));
        case Types.INTEGER:
                        return new Integer(resultSet.getInt(col));
        case Types.BIGINT:
                        return new Long(resultSet.getLong(col));
        case Types.NUMERIC:
                        if( meta.getScale(col)>0 ) {
                            return new Double(resultSet.getDouble(col));
                        }
                        if( meta.getPrecision(col)>=9 ) {
                            return new Long(resultSet.getLong(col));
                        }
                        return new Integer(resultSet.getInt(col));
        case Types.FLOAT:
                        return new Float(resultSet.getFloat(col));
        case Types.DOUBLE:
        case Types.REAL:
        case Types.DECIMAL:
                        return new Double(resultSet.getDouble(col));
    }
    throw new SQLException( StringUtil.format("Data type not yet handled ({0})", StringUtil.toString(type)) ); // $NLX-JdbcDebugUtil.Datatypenotyethandled0-1$
}
 
Example 4
Source File: TestFBBigDecimalField.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void getBigDecimalNull() throws SQLException {
    fieldDescriptor = createIntegerFieldDescriptor(-2);
    field = new FBBigDecimalField(fieldDescriptor, fieldData, Types.NUMERIC);
    toReturnNullExpectations();
    
    assertNull("Expected null result", field.getBigDecimal());
}
 
Example 5
Source File: Column.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get a column value as string using the passed
 * Fromat instance for formatting the output
 *
 * @param format the instance to format the output
 * @return       string version of column content
 */
public String get (Format format, Expression expression) {
	String	rc = null;

	if (isOverwritten) {
		rc = format.format (overwritten == null ? "" : overwritten);
	} else {
		switch (type) {
		case Types.DECIMAL:
		case Types.NUMERIC:
		case Types.DOUBLE:
		case Types.FLOAT:
		case Types.REAL:
			rc = format.format (calc (expression, fval));
			break;
		case Types.BIGINT:
		case Types.INTEGER:
		case Types.SMALLINT:
		case Types.TINYINT:
			rc = format.format (calc (expression, ival));
			break;
		case Types.CHAR:
		case Types.VARCHAR:
		case Types.BLOB:
		case Types.CLOB:
			rc = format.format (sval != null ? calc (expression, sval) : "");
			break;
		case Types.DATE:
		case Types.TIME:
		case Types.TIMESTAMP:
			rc = format.format (calc (expression, dval));
			break;
		default:
			break;
		}
	}
	return format.encode (rc != null ? rc : get (expression));
}
 
Example 6
Source File: TestFBBigDecimalField.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void setBigDecimalShortNull() throws SQLException {
    fieldDescriptor = createShortFieldDescriptor(-1);
    field = new FBBigDecimalField(fieldDescriptor, fieldData, Types.NUMERIC);
    setNullExpectations();
    
    field.setBigDecimal(null);
}
 
Example 7
Source File: FirebirdSpecific.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean isJetelTypeConvertible2sql(int sqlType, DataFieldMetadata field) {
	switch (field.getDataType()) {
	case BOOLEAN:
		switch (sqlType) {
		case Types.CHAR:
		case Types.NUMERIC:
			return true;
		}
	case BYTE:
	case CBYTE:
		switch (sqlType) {
		case Types.VARBINARY:
		case Types.LONGVARBINARY:
			return true;
		}
	case DECIMAL:
	case NUMBER:
	case LONG:
	case INTEGER:
		switch (sqlType) {
		case Types.NUMERIC:
			return true;
		}
	case DATE:
	case DATETIME:
		switch (sqlType) {
		case Types.TIMESTAMP:
			return true;
		}
	default:
		return super.isJetelTypeConvertible2sql(sqlType, field);
	}
}
 
Example 8
Source File: TestFBBigDecimalField.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void setBigDecimalIntegerTooHigh() throws SQLException {
    expectedException.expect(TypeConversionException.class);
    fieldDescriptor = createIntegerFieldDescriptor(-2);
    field = new FBBigDecimalField(fieldDescriptor, fieldData, Types.NUMERIC);
    
    field.setBigDecimal(BigDecimal.valueOf(Integer.MAX_VALUE + 1L, 2));
}
 
Example 9
Source File: TestFBBigDecimalField.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void setBigDecimalInt128TooHigh() throws SQLException {
    expectedException.expect(TypeConversionException.class);
    fieldDescriptor = createInt128FieldDescriptor(-2);
    field = new FBBigDecimalField(fieldDescriptor, fieldData, Types.NUMERIC);
    final String maxValue = "9999999999999999999999999999999999999.99";

    field.setBigDecimal(new BigDecimal(maxValue).add(new BigDecimal("0.01")));
}
 
Example 10
Source File: MysqlDefs.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
public static int javaTypeDetect(int javaType, int scale) {
    switch (javaType) {
        case Types.NUMERIC: {
            if (scale > 0) {
                return Types.DECIMAL;
            } else {
                return javaType;
            }
        }
        default: {
            return javaType;
        }
    }

}
 
Example 11
Source File: EventCallbackListener.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Build the query string for updating the backend database
 * 
 * @param event
 *          the callback event
 * @return SQL update query to the backend database
 * @throws SQLException
 */
private String buildUpdateQuery(Event event) throws SQLException {

  ResultSetMetaData meta = event.getResultSetMetaData();
  int[] modifiedCols = event.getModifiedColumns();
  List<Object> newRow = event.getNewRow();

  StringBuilder query = new StringBuilder();
  if (event.getModifiedColumns() == null) {
    throw new SQLException("Nothing is updated.");
  }

  // query.append("UPDATE " + meta.getSchemaName(1) + "." +
  // meta.getTableName(1));
  query.append("UPDATE " + meta.getSchemaName(1) + "." + meta.getTableName(1) + "_ONE");
  query.append(" SET ");

  for (int i = 0; i < modifiedCols.length; i++) {
    query.append(meta.getColumnName(modifiedCols[i]) + "=");
    int type = meta.getColumnType(modifiedCols[i]);
    Object value = newRow.get(modifiedCols[i] - 1);

    switch (type) {
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.NUMERIC:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.INTEGER:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
    case Types.TIMESTAMP:
      query.append(value + ",");
      break;
    default:
      query.append("'" + value + "',");
    }
  }

  query.delete(query.length() - 1, query.length());

  // add where clause "where pkName1=pkValue1 and pkName2=pkValue2 ... ;"

  Object[] pkValue = event.getPrimaryKey();

  String[] keys = primaryKeys.split(",");
  if (keys.length > 0) {
    query.append(" WHERE ");
    for (int i = 0; i < keys.length; i++) {
      String keyName = keys[i];
      query.append(keyName).append("=");
      if (pkValue[i] instanceof String) {
        query.append("'" + pkValue[i] + "'");
      } else {
        query.append(pkValue[i]);
      }
      if (i < keys.length - 1) {
        query.append(" AND ");
      }
    }
  }

  return query.toString();
}
 
Example 12
Source File: SqlUpdateTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public ConstructorUpdater() {
	super(dataSource, UPDATE_OBJECTS,
			new int[] {Types.NUMERIC, Types.NUMERIC, Types.VARCHAR, Types.BOOLEAN });
	compile();
}
 
Example 13
Source File: TestAgainstLiveDatabaseBase.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Asserts that the two given columns are equal.
 * 
 * @param expected      The expected column
 * @param actual        The actual column
 * @param caseSensitive Whether case matters when comparing
 */
protected void assertEquals(Column expected, Column actual, boolean caseSensitive)
{
    if (caseSensitive)
    {
        assertEquals("Column names do not match.",
                     getPlatform().getSqlBuilder().shortenName(expected.getName(), getSqlBuilder().getMaxColumnNameLength()),
                     getPlatform().getSqlBuilder().shortenName(actual.getName(), getSqlBuilder().getMaxColumnNameLength()));
    }
    else
    {
        assertEquals("Column names do not match (ignoring case).",
                     getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(), getSqlBuilder().getMaxColumnNameLength()),
                     getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(), getSqlBuilder().getMaxColumnNameLength()));
    }
    assertEquals("Primary key status not the same for column "+actual.getName()+".",
                 expected.isPrimaryKey(),
                 actual.isPrimaryKey());
    assertEquals("Required status not the same for column "+actual.getName()+".",
                 expected.isRequired(),
                 actual.isRequired());
    if (getPlatformInfo().getIdentityStatusReadingSupported())
    {
        // we're only comparing this if the platform can actually read the
        // auto-increment status back from an existing database
        assertEquals("Auto-increment status not the same for column "+actual.getName()+".",
                     expected.isAutoIncrement(),
                     actual.isAutoIncrement());
    }
    assertEquals("Type not the same for column "+actual.getName()+".",
                 expected.getType(),
                 actual.getType());
    assertEquals("Type code not the same for column "+actual.getName()+".",
                 expected.getTypeCode(),
                 actual.getTypeCode());
    assertEquals("Parsed default values do not match for column "+actual.getName()+".",
                 expected.getParsedDefaultValue(),
                 actual.getParsedDefaultValue());

    // comparing the size makes only sense for types where it is relevant
    if ((expected.getTypeCode() == Types.NUMERIC) ||
        (expected.getTypeCode() == Types.DECIMAL))
    {
        assertEquals("Precision not the same for column "+actual.getName()+".",
                     expected.getSizeAsInt(),
                     actual.getSizeAsInt());
        assertEquals("Scale not the same for column "+actual.getName()+".",
                     expected.getScale(),
                     actual.getScale());
    }
    else if ((expected.getTypeCode() == Types.CHAR) ||
             (expected.getTypeCode() == Types.VARCHAR) ||
             (expected.getTypeCode() == Types.BINARY) ||
             (expected.getTypeCode() == Types.VARBINARY))
    {
        assertEquals("Size not the same for column "+actual.getName()+".",
                     expected.getSize(),
                     actual.getSize());
    }
}
 
Example 14
Source File: MSSqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected String getValueAsString(Column column, Object value)
{
    if (value == null)
    {
        return "NULL";
    }

    StringBuilder result = new StringBuilder();

    switch (column.getTypeCode())
    {
        case Types.REAL:
        case Types.NUMERIC:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.DECIMAL:
            // SQL Server does not want quotes around the value
            if (!(value instanceof String) && (getValueNumberFormat() != null))
            {
                result.append(getValueNumberFormat().format(value));
            }
            else
            {
                result.append(value.toString());
            }
            break;
        case Types.DATE:
            result.append("CAST(");
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(value instanceof String ? (String)value : getValueDateFormat().format(value));
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(" AS datetime)");
            break;
        case Types.TIME:
            result.append("CAST(");
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(value instanceof String ? (String)value : getValueTimeFormat().format(value));
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(" AS datetime)");
            break;
        case Types.TIMESTAMP:
            result.append("CAST(");
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(value.toString());
            result.append(getPlatformInfo().getValueQuoteToken());
            result.append(" AS datetime)");
            break;
    }
    return super.getValueAsString(column, value);
}
 
Example 15
Source File: SQLiteCursor.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 16
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get {@link GFXDType} for given JDBC {@link Types}.
 */
public static GFXDType getThriftSQLType(int jdbcType) {
  switch (jdbcType) {
    case Types.ARRAY:
      return GFXDType.ARRAY;
    case Types.BIGINT:
      return GFXDType.BIGINT;
    case Types.BINARY:
      return GFXDType.BINARY;
    case Types.BIT:
      return GFXDType.BOOLEAN;
    case Types.BLOB:
      return GFXDType.BLOB;
    case Types.BOOLEAN:
      return GFXDType.BOOLEAN;
    case Types.CHAR:
      return GFXDType.CHAR;
    case Types.CLOB:
      return GFXDType.CLOB;
    case Types.DATALINK:
      return GFXDType.DATALINK;
    case Types.DATE:
      return GFXDType.DATE;
    case Types.DECIMAL:
      return GFXDType.DECIMAL;
    case Types.DISTINCT:
      return GFXDType.DISTINCT;
    case Types.DOUBLE:
      return GFXDType.DOUBLE;
    case Types.FLOAT:
      return GFXDType.FLOAT;
    case Types.INTEGER:
      return GFXDType.INTEGER;
    case Types.JAVA_OBJECT:
      return GFXDType.JAVA_OBJECT;
    case TYPE_JSON_OBJECT:
      return GFXDType.JSON_OBJECT;
    case Types.LONGNVARCHAR:
      return GFXDType.LONGNVARCHAR;
    case Types.LONGVARBINARY:
      return GFXDType.LONGVARBINARY;
    case Types.LONGVARCHAR:
      return GFXDType.LONGVARCHAR;
    case Types.NCHAR:
      return GFXDType.NCHAR;
    case Types.NCLOB:
      return GFXDType.NCLOB;
    case Types.NULL:
      return GFXDType.NULLTYPE;
    case Types.NUMERIC:
      return GFXDType.DECIMAL;
    case Types.NVARCHAR:
      return GFXDType.NVARCHAR;
    case Types.OTHER:
      return GFXDType.OTHER;
    case TYPE_PDX_OBJECT:
      return GFXDType.PDX_OBJECT;
    case Types.REAL:
      return GFXDType.REAL;
    case Types.REF:
      return GFXDType.REF;
    case Types.ROWID:
      return GFXDType.ROWID;
    case Types.SMALLINT:
      return GFXDType.SMALLINT;
    case Types.SQLXML:
      return GFXDType.SQLXML;
    case Types.STRUCT:
      return GFXDType.STRUCT;
    case Types.TIME:
      return GFXDType.TIME;
    case Types.TIMESTAMP:
      return GFXDType.TIMESTAMP;
    case Types.TINYINT:
      return GFXDType.TINYINT;
    case Types.VARBINARY:
      return GFXDType.VARBINARY;
    case Types.VARCHAR:
      return GFXDType.VARCHAR;
    default:
      return GFXDType.OTHER;
  }
}
 
Example 17
Source File: GenericTableMetaDataProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method supporting the metadata processing for a table's columns
 */
private void processTableColumns(DatabaseMetaData databaseMetaData, TableMetaData tmd) {
	ResultSet tableColumns = null;
	String metaDataCatalogName = metaDataCatalogNameToUse(tmd.getCatalogName());
	String metaDataSchemaName = metaDataSchemaNameToUse(tmd.getSchemaName());
	String metaDataTableName = tableNameToUse(tmd.getTableName());
	if (logger.isDebugEnabled()) {
		logger.debug("Retrieving metadata for " + metaDataCatalogName + '/' +
				metaDataSchemaName + '/' + metaDataTableName);
	}
	try {
		tableColumns = databaseMetaData.getColumns(
				metaDataCatalogName, metaDataSchemaName, metaDataTableName, null);
		while (tableColumns.next()) {
			String columnName = tableColumns.getString("COLUMN_NAME");
			int dataType = tableColumns.getInt("DATA_TYPE");
			if (dataType == Types.DECIMAL) {
				String typeName = tableColumns.getString("TYPE_NAME");
				int decimalDigits = tableColumns.getInt("DECIMAL_DIGITS");
				// Override a DECIMAL data type for no-decimal numerics
				// (this is for better Oracle support where there have been issues
				// using DECIMAL for certain inserts (see SPR-6912))
				if ("NUMBER".equals(typeName) && decimalDigits == 0) {
					dataType = Types.NUMERIC;
					if (logger.isDebugEnabled()) {
						logger.debug("Overriding metadata: " + columnName + " now NUMERIC instead of DECIMAL");
					}
				}
			}
			boolean nullable = tableColumns.getBoolean("NULLABLE");
			TableParameterMetaData meta = new TableParameterMetaData(columnName, dataType, nullable);
			this.tableParameterMetaData.add(meta);
			if (logger.isDebugEnabled()) {
				logger.debug("Retrieved metadata: " + meta.getParameterName() + " " +
						meta.getSqlType() + " " + meta.isNullable());
			}
		}
	}
	catch (SQLException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Error while retrieving metadata for table columns: " + ex.getMessage());
		}
	}
	finally {
		JdbcUtils.closeResultSet(tableColumns);
	}
}
 
Example 18
Source File: ResultSetRecordSet.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static RecordFieldType getFieldType(final int sqlType, final String valueClassName) {
    switch (sqlType) {
        case Types.BIGINT:
        case Types.ROWID:
            return RecordFieldType.LONG;
        case Types.BIT:
        case Types.BOOLEAN:
            return RecordFieldType.BOOLEAN;
        case Types.CHAR:
            return RecordFieldType.CHAR;
        case Types.DATE:
            return RecordFieldType.DATE;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return RecordFieldType.DECIMAL;
        case Types.DOUBLE:
        case Types.REAL:
            return RecordFieldType.DOUBLE;
        case Types.FLOAT:
            return RecordFieldType.FLOAT;
        case Types.INTEGER:
            return RecordFieldType.INT;
        case Types.SMALLINT:
            return RecordFieldType.SHORT;
        case Types.TINYINT:
            return RecordFieldType.BYTE;
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NULL:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return RecordFieldType.STRING;
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            if (STRING_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.STRING;
            }
            if (INT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.INT;
            }
            if (LONG_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.LONG;
            }
            if (DATE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DATE;
            }
            if (FLOAT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.FLOAT;
            }
            if (DOUBLE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DOUBLE;
            }
            if (BIGDECIMAL_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DECIMAL;
            }

            return RecordFieldType.RECORD;
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
            return RecordFieldType.TIME;
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
        case -101: // Oracle's TIMESTAMP WITH TIME ZONE
        case -102: // Oracle's TIMESTAMP WITH LOCAL TIME ZONE
            return RecordFieldType.TIMESTAMP;
    }

    return RecordFieldType.STRING;
}
 
Example 19
Source File: PrestoResultSetMetaData.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public String getColumnClassName(int column)
        throws SQLException
{
    // see javax.sql.rowset.RowSetMetaDataImpl
    switch (column(column).getColumnType()) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            return BigDecimal.class.getName();
        case Types.BOOLEAN:
        case Types.BIT:
            return Boolean.class.getName();
        case Types.TINYINT:
            return Byte.class.getName();
        case Types.SMALLINT:
            return Short.class.getName();
        case Types.INTEGER:
            return Integer.class.getName();
        case Types.BIGINT:
            return Long.class.getName();
        case Types.REAL:
            return Float.class.getName();
        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class.getName();
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return "byte[]";
        case Types.DATE:
            return Date.class.getName();
        case Types.TIME:
            return Time.class.getName();
        case Types.TIMESTAMP:
            return Timestamp.class.getName();
        case Types.BLOB:
            return Blob.class.getName();
        case Types.CLOB:
            return Clob.class.getName();
        case Types.ARRAY:
            return Array.class.getName();
    }
    return String.class.getName();
}
 
Example 20
Source File: MetaMapping.java    From mybatis-daoj with Apache License 2.0 4 votes vote down vote up
/**
 * 把列类型映射为类属性类型
 *
 * @param colType
 * @return
 * @throws Exception
 */
private Class reflectToFieldType(int colType, int scale) throws Exception {

    switch (colType) {
        case Types.BIT:
            return Boolean.class;

        case Types.TINYINT:
            return Byte.class;
        case Types.SMALLINT:
            return Short.class;
        case Types.INTEGER:
            return Integer.class;
        case Types.BIGINT:
            return Long.class;

        case Types.FLOAT:
            return Float.class;
        case Types.REAL:
            return Double.class;
        case Types.DOUBLE:
            return Double.class;
        case Types.NUMERIC:
            if (scale == 0) {
                return Long.class;
            } else {
                return java.math.BigDecimal.class;
            }
        case Types.DECIMAL:
            if (scale == 0) {
                return Long.class;
            } else {
                return java.math.BigDecimal.class;
            }
        case Types.CHAR:
            return String.class;
        case Types.VARCHAR:
            return String.class;
        case Types.LONGVARCHAR:
            return String.class;

        case Types.DATE:
            return java.sql.Date.class;
        case Types.TIME:
            return java.sql.Time.class;
        case Types.TIMESTAMP:
            return java.sql.Timestamp.class;

        case Types.BINARY:
            return byte[].class;
        case Types.VARBINARY:
            return byte[].class;
        case Types.LONGVARBINARY:
            return byte[].class;

        case Types.BLOB:
            return byte[].class;
        case Types.CLOB:
            return byte[].class;
    }

    throw new Exception("不能识别的列类型:" + colType);
}