Java Code Examples for java.sql.Types#DECIMAL

The following examples show how to use java.sql.Types#DECIMAL . 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: SqlMakeTools.java    From GyJdbc with Apache License 2.0 6 votes vote down vote up
private static int getTypes(Field arg) {
    arg.setAccessible(true); // 暴力反射
    if (String.class.equals(arg.getType())) {
        return Types.VARCHAR;
    } else if (int.class.equals(arg.getType()) || Integer.class.equals(arg.getType())) {
        return Types.INTEGER;
    } else if (double.class.equals(arg.getType()) || Double.class.equals(arg.getType())) {
        return Types.DOUBLE;
    } else if (java.util.Date.class.isAssignableFrom(arg.getType())) {
        return Types.TIMESTAMP;
    } else if (long.class.equals(arg.getType()) || Long.class.equals(arg.getType())) {
        return Types.BIGINT;
    } else if (float.class.equals(arg.getType()) || Float.class.equals(arg.getType())) {
        return Types.FLOAT;
    } else if (boolean.class.equals(arg.getType()) || Boolean.class.equals(arg.getType())) {
        return Types.BOOLEAN;
    } else if (short.class.equals(arg.getType()) || Short.class.equals(arg.getType())) {
        return Types.INTEGER;
    } else if (byte.class.equals(arg.getType()) || Byte.class.equals(arg.getType())) {
        return Types.INTEGER;
    } else if (BigDecimal.class.equals(arg.getType())) {
        return Types.DECIMAL;
    } else {
        return Types.OTHER;
    }
}
 
Example 2
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected String getSqlType(Column column) {
  // convert back to unspecified precision if required
  if (column.getTypeCode() == Types.NUMERIC
      || column.getTypeCode() == Types.DECIMAL) {
    if (column.isUnspecifiedPrecision()) {
      if (column.getScale() == 0) {
        return "NUMBER";
      }
      else {
        return "NUMBER(*," + column.getScale() + ')';
      }
    }
  }
  return super.getSqlType(column);
}
 
Example 3
Source File: DataTypeDescriptor.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static boolean isNumericType(int jdbcType) {

		switch (jdbcType) {
		case Types.BIT:
		case Types.BOOLEAN:
		case Types.TINYINT:
		case Types.SMALLINT:
		case Types.INTEGER:
		case Types.BIGINT:
		case Types.REAL:
		case Types.FLOAT:
		case Types.DOUBLE:
		case Types.DECIMAL:
		case Types.NUMERIC:
			return true;
		default:
			return false;
		}
	}
 
Example 4
Source File: SQLDecimal.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get a BigDecimal representing the value of a DataValueDescriptor
 * @param value Non-null value to be converted
 * @return BigDecimal value
 * @throws StandardException Invalid conversion or out of range.
 */
public static BigDecimal getBigDecimal(DataValueDescriptor value) throws StandardException
{
	if (SanityManager.DEBUG)
	{
		if (value.isNull())
			SanityManager.THROWASSERT("NULL value passed to SQLDecimal.getBigDecimal");
	}

	switch (value.typeToBigDecimal())
	{
	case Types.DECIMAL:
		return (BigDecimal) value.getObject();
	case Types.CHAR:
		try {
			return new BigDecimal(value.getString().trim());
		} catch (NumberFormatException nfe) {
			throw StandardException.newException(SQLState.LANG_FORMAT_EXCEPTION, "java.math.BigDecimal");
		}
	case Types.BIGINT:
		return BigDecimal.valueOf(value.getLong());
	default:
		if (SanityManager.DEBUG)
			SanityManager.THROWASSERT("invalid return from " + value.getClass() + ".typeToBigDecimal() " + value.typeToBigDecimal());
		return null;
	}
}
 
Example 5
Source File: JdbcUtils.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given SQL type is numeric.
 * @param sqlType the SQL type to be checked
 * @return whether the type is numeric
 */
public static boolean isNumeric(int sqlType) {
	return Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType ||
			Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType ||
			Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType ||
			Types.TINYINT == sqlType;
}
 
Example 6
Source File: JdbcTypeConverterTest.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMutualConversion() {
    int[] types = new int[]{ Types.VARCHAR, Types.BOOLEAN,
            Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT, Types.FLOAT,
            Types.DOUBLE, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.DECIMAL, Types.BINARY};

    for (int type : types) {
        TypeInformation<?> flinkType = JdbcTypeConverter.getFlinkType(type);
        int sqlType = JdbcTypeConverter.getIntegerSqlType(flinkType);
        Assert.assertEquals(type, sqlType);
    }
}
 
Example 7
Source File: TypeValidator.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
protected static int baseJoinType(TClass tclass) {
    int jdbcType = tclass.jdbcType();
    switch (jdbcType) {
    case Types.BIGINT:
        if (tclass.isUnsigned())
            return Types.OTHER;
    /* else falls through */
    case Types.TINYINT:
    case Types.INTEGER:
    case Types.SMALLINT:
        return Types.BIGINT;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return Types.DECIMAL;
    case Types.FLOAT:
    case Types.REAL:
    case Types.DOUBLE:
        return Types.DOUBLE;
    case Types.CHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.VARCHAR:
        return Types.VARCHAR;
    case Types.LONGNVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return Types.LONGVARCHAR;
    case Types.BINARY:
    case Types.BIT:
    case Types.VARBINARY:
        return Types.VARBINARY;
    case Types.LONGVARBINARY:
        return Types.LONGVARBINARY;
    default:
        return jdbcType;
    }
}
 
Example 8
Source File: SQLServerStorageManager.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte convertLocalTypeToGSN(int jdbcType, int precision) {
    switch (jdbcType) {
        case Types.BIGINT:
            return DataTypes.BIGINT;
        case Types.INTEGER:
            return DataTypes.INTEGER;
        case Types.SMALLINT:
            return DataTypes.SMALLINT;
        case Types.TINYINT:
            return DataTypes.TINYINT;
        case Types.VARCHAR:
            return DataTypes.VARCHAR;
        case Types.CHAR:
            return DataTypes.CHAR;
        case Types.DOUBLE:
        case Types.DECIMAL:    // This is needed for doing aggregates in datadownload servlet.
            return DataTypes.DOUBLE;
        case Types.REAL:
        	return DataTypes.FLOAT;
        case Types.BINARY:
        case Types.BLOB:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return DataTypes.BINARY;
        default:
            logger.error("The type can't be converted to GSN form : " + jdbcType);
            break;
    }
    return -100;
}
 
Example 9
Source File: DataTypes.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
/**
  * throws runtime exception if the type conversion fails.
  * @param sqlType
  * @return
  */
 public static byte SQLTypeToGSNTypeSimplified(int sqlType) {
  if (sqlType == Types.BIGINT || sqlType == Types.SMALLINT || sqlType == Types.DOUBLE || sqlType==Types.INTEGER || sqlType == Types.DECIMAL||sqlType == Types.REAL || sqlType == Types.FLOAT|| sqlType == Types.NUMERIC )
	return  DataTypes.DOUBLE;
else if (sqlType == Types.VARCHAR || sqlType == Types.CHAR|| sqlType == Types.LONGNVARCHAR || sqlType == Types.LONGVARCHAR || sqlType== Types.NCHAR )
	return  DataTypes.VARCHAR;
else if (sqlType == Types.BINARY || sqlType == Types.BLOB|| sqlType == Types.VARBINARY )
	return  DataTypes.BINARY;
  throw new RuntimeException("Can't convert SQL type id of: "+sqlType+ " to GSN type id.");
 }
 
Example 10
Source File: JavaTypeResolver.java    From uncode-dal-all with GNU General Public License v2.0 5 votes vote down vote up
public static JavaType calculateJavaType(int jdbcType) {
    if (typeMap != null && typeMap.size() == 0) {
        init();
    }
    JavaType type = typeMap.get(jdbcType);

    if (type == null) {
        switch (jdbcType) {
        case Types.DECIMAL:
        case Types.NUMERIC:
        }
    }
    return type;
}
 
Example 11
Source File: UnaryDateTimestampOperatorNode.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Called by UnaryOperatorNode.bindExpression.
 * <p/>
 * If the operand is a constant then evaluate the function at compile time. Otherwise,
 * if the operand input type is the same as the output type then discard this node altogether.
 * If the function is "date" and the input is a timestamp then change this node to a cast.
 *
 * @param fromList        The FROM list for the query this
 *                        expression is in, for binding columns.
 * @param subqueryList    The subquery list being built as we find SubqueryNodes
 * @param aggregateVector The aggregate vector being built as we find AggregateNodes
 * @throws StandardException Thrown on error
 * @return The new top of the expression tree.
 */
@Override
public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                List<AggregateNode> aggregateVector) throws StandardException{
    boolean isIdentity=false; // Is this function the identity operator?
    boolean operandIsNumber=false;

    bindOperand(fromList,subqueryList,aggregateVector);
    DataTypeDescriptor operandType=operand.getTypeServices();
    switch(operandType.getJDBCTypeId()){
        case Types.BIGINT:
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
        case Types.DECIMAL:
        case Types.NUMERIC:
        case Types.DOUBLE:
        case Types.FLOAT:
            if(TIMESTAMP_METHOD_NAME.equals(methodName))
                invalidOperandType();
            operandIsNumber=true;
            break;

        case Types.CHAR:
        case Types.VARCHAR:
            break;

        case Types.DATE:
            if(!TIMESTAMP_METHOD_NAME.equals(methodName))
                isIdentity=true;
            break;

        case Types.NULL:
            break;

        case Types.TIMESTAMP:
            if(TIMESTAMP_METHOD_NAME.equals(methodName))
                isIdentity=true;
            break;

        default:
            invalidOperandType();
    }

    if(operand instanceof ConstantNode){
        DataValueFactory dvf=getLanguageConnectionContext().getDataValueFactory();
        DataValueDescriptor sourceValue=((ConstantNode)operand).getValue();
        DataValueDescriptor destValue=null;
        if(sourceValue.isNull()){
            destValue=(TIMESTAMP_METHOD_NAME.equals(methodName))
                    ?dvf.getNullTimestamp((DateTimeDataValue)null)
                    :dvf.getNullDate((DateTimeDataValue)null);
        }else{
            destValue=(TIMESTAMP_METHOD_NAME.equals(methodName))
                    ?dvf.getTimestamp(sourceValue):dvf.getDate(sourceValue);
        }
        return (ValueNode)getNodeFactory().getNode(C_NodeTypes.USERTYPE_CONSTANT_NODE,
                destValue,getContextManager());
    }

    if(isIdentity)
        return operand;
    return this;
}
 
Example 12
Source File: AbstractStringRowIterator.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object getObject(int columnIndex) {
    int columnType = mycatRowMetaData.getColumnType(columnIndex);
    switch (columnType) {
        case Types.NUMERIC: {

        }
        case Types.DECIMAL: {
            return this.getBigDecimal(columnIndex);
        }
        case Types.BIT: {
            return this.getBoolean(columnIndex);
        }
        case Types.TINYINT: {
            return this.getByte(columnIndex);
        }
        case Types.SMALLINT: {
            return this.getShort(columnIndex);
        }
        case Types.INTEGER: {
            return this.getInt(columnIndex);
        }
        case Types.BIGINT: {
            return this.getLong(columnIndex);
        }
        case Types.REAL: {
            return this.getFloat(columnIndex);
        }
        case Types.FLOAT: {

        }
        case Types.DOUBLE: {
            return this.getDouble(columnIndex);
        }
        case Types.BINARY: {

        }
        case Types.VARBINARY: {

        }
        case Types.LONGVARBINARY: {
            return this.getBytes(columnIndex);
        }
        case Types.DATE: {
            return this.getDate(columnIndex);
        }
        case Types.TIME: {
            return this.getTime(columnIndex);
        }
        case Types.TIMESTAMP: {
            return this.getTimestamp(columnIndex);
        }
        case Types.CHAR: {

        }
        case Types.VARCHAR: {

        }
        case Types.LONGVARCHAR: {
            return this.getString(columnIndex);
        }
        case Types.BLOB: {

        }
        case Types.CLOB: {
            return this.getBytes(columnIndex);
        }
        case Types.NULL: {
            return null;
        }
        default:
            throw new RuntimeException("unsupport!");
    }
}
 
Example 13
Source File: StandardAnsiSqlAggregationFunctions.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type firstArgumentType, Mapping mapping) {
	final int jdbcType = determineJdbcTypeCode( firstArgumentType, mapping );

	// First allow the actual type to control the return value; the underlying sqltype could
	// actually be different
	if ( firstArgumentType == StandardBasicTypes.BIG_INTEGER ) {
		return StandardBasicTypes.BIG_INTEGER;
	}
	else if ( firstArgumentType == StandardBasicTypes.BIG_DECIMAL ) {
		return StandardBasicTypes.BIG_DECIMAL;
	}
	else if ( firstArgumentType == StandardBasicTypes.LONG
			|| firstArgumentType == StandardBasicTypes.SHORT
			|| firstArgumentType == StandardBasicTypes.INTEGER ) {
		return StandardBasicTypes.LONG;
	}
	else if ( firstArgumentType == StandardBasicTypes.FLOAT || firstArgumentType == StandardBasicTypes.DOUBLE)  {
		return StandardBasicTypes.DOUBLE;
	}

	// finally use the jdbcType if == on Hibernate types did not find a match.
	//
	//	IMPL NOTE : we do not match on Types.NUMERIC because it could be either, so we fall-through to the
	// 		first argument type
	if ( jdbcType == Types.FLOAT
			|| jdbcType == Types.DOUBLE
			|| jdbcType == Types.DECIMAL
			|| jdbcType == Types.REAL) {
		return StandardBasicTypes.DOUBLE;
	}
	else if ( jdbcType == Types.BIGINT
			|| jdbcType == Types.INTEGER
			|| jdbcType == Types.SMALLINT
			|| jdbcType == Types.TINYINT ) {
		return StandardBasicTypes.LONG;
	}

	// as a last resort, return the type of the first argument
	return firstArgumentType;
}
 
Example 14
Source File: PDecimal.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private PDecimal() {
  super("DECIMAL", Types.DECIMAL, BigDecimal.class, null, 8);
}
 
Example 15
Source File: SQLTypeUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Convert sql types to String for display
 *
 * @param sqlType the type number from java.sql.Types
 * @return the type name
 */
static public String getSqlTypeString(int sqlType) {
    switch (sqlType) {
        case Types.BIGINT:
            return "BIGINT"; //NOI18N
        case Types.BINARY:
            return "BINARY"; //NOI18N
        case Types.BIT:
            return "BIT"; //NOI18N
        case Types.NCHAR:
            return "NCHAR"; //NOI18N
        case Types.CHAR:
            return "CHAR"; //NOI18N
        case Types.DATE:
            return "DATE"; //NOI18N
        case Types.DECIMAL:
            return "DECIMAL"; //NOI18N
        case Types.DOUBLE:
            return "DOUBLE"; //NOI18N
        case Types.FLOAT:
            return "FLOAT"; //NOI18N
        case Types.INTEGER:
            return "INTEGER"; //NOI18N
        case Types.LONGVARBINARY:
            return "LONGVARBINARY"; //NOI18N
        case Types.LONGNVARCHAR:
            return "LONGNVARCHAR"; //NOI18N
        case Types.LONGVARCHAR:
            return "LONGVARCHAR"; //NOI18N
        case Types.NULL:
            return "NULL"; //NOI18N
        case Types.NUMERIC:
            return "NUMERIC"; //NOI18N
        case Types.OTHER:
            return "OTHER"; //NOI18N
        case Types.REAL:
            return "REAL"; //NOI18N
        case Types.SMALLINT:
            return "SMALLINT"; //NOI18N
        case Types.TIME:
            return "TIME"; //NOI18N
        case Types.TIMESTAMP:
            return "TIMESTAMP"; //NOI18N
        case Types.TINYINT:
            return "TINYINT"; //NOI18N
        case Types.VARBINARY:
            return "VARBINARY"; //NOI18N
        case Types.NVARCHAR:
            return "NVARCHAR";
        case Types.VARCHAR:
            return "VARCHAR"; //NOI18N
        case Types.JAVA_OBJECT:
            return "JAVA_OBJECT"; //NOI18N
        case Types.DISTINCT:
            return "DISTINCT"; //NOI18N
        case Types.STRUCT:
            return "STRUCT"; //NOI18N
        case Types.ARRAY:
            return "ARRAY"; //NOI18N
        case Types.BLOB:
            return "BLOB"; //NOI18N
        case Types.NCLOB:
            return "NCLOB";
        case Types.CLOB:
            return "CLOB"; //NOI18N
        case Types.REF:
            return "REF"; //NOI18N
        default:
            Logger.getLogger(SQLTypeUtil.class.getName()).log(Level.WARNING, "Unknown JDBC column type: {0}. Returns null.", sqlType);
            return "UNKNOWN"; //NOI18N
    }
}
 
Example 16
Source File: EventCallbackWriter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Build the query string to insert a row to the backend database
 * 
 * @param event
 *          the callback event
 * @return SQL query string to insert a row to the back-end database
 * @throws SQLException
 */
private String buildInsertQuery(Event event) throws SQLException {

  ResultSetMetaData meta = event.getResultSetMetaData();

  List<Object> newRow = event.getNewRow();

  StringBuilder query = new StringBuilder();

  // insert into table_name values (...); assume
  // Note: insert into table_name(col1, col2 ...) values (...) is not
  // supported here
  //query.append("INSERT INTO " + meta.getSchemaName(1) + "."
  //    + meta.getTableName(1) + " VALUES (");
  query.append("INSERT INTO " + meta.getSchemaName(1) + "." + meta.getTableName(1) + "_ONE VALUES (");

  for (int i = 1; i <= meta.getColumnCount(); i++) {

    int type = meta.getColumnType(i);

    Object value = newRow.get(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());

  query.append(");");

  return query.toString();

}
 
Example 17
Source File: JdbcTypeConverter.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Converts from the Firebird type, subtype and scale to the JDBC type value from {@link java.sql.Types}.
 * <p>
 * This method is not capable of identifying {@link java.sql.Types#ROWID}; this will be identified
 * as {@link java.sql.Types#BINARY} instead.
 * </p>
 *
 * @param firebirdType
 *         Firebird type value (from {@link ISCConstants} {@code SQL_*} with or without nullable bit set
 * @param subtype
 *         Subtype
 * @param scale
 *         Scale
 * @return JDBC type, or {@link Types#OTHER} for unknown types
 */
public static int fromFirebirdToJdbcType(int firebirdType, int subtype, int scale) {
    firebirdType = firebirdType & ~1;

    switch (firebirdType) {
    case ISCConstants.SQL_SHORT:
    case ISCConstants.SQL_LONG:
    case ISCConstants.SQL_INT64:
    case ISCConstants.SQL_DOUBLE:
    case ISCConstants.SQL_D_FLOAT:
    case ISCConstants.SQL_INT128:
        if (subtype == SUBTYPE_NUMERIC || (subtype == 0 && scale < 0)) {
            return Types.NUMERIC;
        } else if (subtype == SUBTYPE_DECIMAL) {
            return Types.DECIMAL;
        } else {
            switch (firebirdType) {
            case ISCConstants.SQL_SHORT:
                return Types.SMALLINT;
            case ISCConstants.SQL_LONG:
                return Types.INTEGER;
            case ISCConstants.SQL_INT64:
                return Types.BIGINT;
            case ISCConstants.SQL_DOUBLE:
            case ISCConstants.SQL_D_FLOAT:
                return Types.DOUBLE;
            case ISCConstants.SQL_INT128:
                return Types.DECIMAL;
            }
        }
    case ISCConstants.SQL_FLOAT:
        return Types.FLOAT;
    case ISCConstants.SQL_DEC16:
    case ISCConstants.SQL_DEC34:
        return JaybirdTypeCodes.DECFLOAT;
    case ISCConstants.SQL_TEXT:
        if (subtype == ISCConstants.CS_BINARY) {
            return Types.BINARY;
        } else {
            return Types.CHAR;
        }
    case ISCConstants.SQL_VARYING:
        if (subtype == ISCConstants.CS_BINARY) {
            return Types.VARBINARY;
        } else {
            return Types.VARCHAR;
        }
    case ISCConstants.SQL_TIMESTAMP:
        return Types.TIMESTAMP;
    case ISCConstants.SQL_TYPE_TIME:
        return Types.TIME;
    case ISCConstants.SQL_TYPE_DATE:
        return Types.DATE;
    case ISCConstants.SQL_TIMESTAMP_TZ:
    case ISCConstants.SQL_TIMESTAMP_TZ_EX:
        return Types.TIMESTAMP_WITH_TIMEZONE;
    case ISCConstants.SQL_TIME_TZ:
    case ISCConstants.SQL_TIME_TZ_EX:
        return Types.TIME_WITH_TIMEZONE;
    case ISCConstants.SQL_BLOB:
        if (subtype < 0) {
            return Types.BLOB;
        } else if (subtype == ISCConstants.BLOB_SUB_TYPE_TEXT) {
            return Types.LONGVARCHAR;
        } else { // if (subtype == 0 || subtype > 1)
            return Types.LONGVARBINARY;
        }
    case ISCConstants.SQL_BOOLEAN:
        return Types.BOOLEAN;
    case ISCConstants.SQL_NULL:
        return Types.NULL;
    case ISCConstants.SQL_ARRAY:
        return Types.ARRAY;
    case ISCConstants.SQL_QUAD:
    default:
        return Types.OTHER;
    }
}
 
Example 18
Source File: EventCallbackListener.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Build the query string to insert a row to the backend database
 * 
 * @param event
 *          the callback event
 * @return SQL query string to insert a row to the back-end database
 * @throws SQLException
 */
private String buildInsertQuery(Event event) throws SQLException {

  ResultSetMetaData meta = event.getResultSetMetaData();

  List<Object> newRow = event.getNewRow();

  StringBuilder query = new StringBuilder();

  // insert into table_name values (...); assume
  // Note: insert into table_name(col1, col2 ...) values (...) is not
  // supported here
  //query.append("INSERT INTO " + meta.getSchemaName(1) + "."
  //    + meta.getTableName(1) + " VALUES (");
  query.append("INSERT INTO " + meta.getSchemaName(1) + "." + meta.getTableName(1) + "_ONE VALUES (");

  for (int i = 1; i <= meta.getColumnCount(); i++) {

    int type = meta.getColumnType(i);

    Object value = newRow.get(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());

  query.append(");");

  return query.toString();

}
 
Example 19
Source File: GeneratorUtils.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
public static String findClosestJavaTypeFor(int aJdbcType, boolean aNullable) {
	switch (aJdbcType) {
		case Types.CHAR:
			return "String";
		case Types.VARCHAR:
			return "String";
		case Types.LONGVARCHAR:
			return "String";
		case Types.NUMERIC:
			return "java.math.BigDecimal";
		case Types.DECIMAL:
			return "java.math.BigDecimal";
		case Types.BIT:
			return aNullable ? "Boolean" : "boolean";
		case Types.TINYINT:
			return aNullable ? "Byte" : "byte";
		case Types.SMALLINT:
			return aNullable ? "Short" : "short";
		case Types.INTEGER:
			return aNullable ? "Integer" : "int";
		case Types.BIGINT:
			return aNullable ? "Long" : "long";
		case Types.REAL:
			return aNullable ? "Float" : "float";
		case Types.FLOAT:
			return aNullable ? "Double" : "double";
		case Types.DOUBLE:
			return aNullable ? "Double" : "double";
		case Types.BINARY:
			return "byte[]";
		case Types.VARBINARY:
			return "byte[]";
		case Types.LONGVARBINARY:
			return "byte[]";
		case Types.DATE:
			return "java.sql.Date";
		case Types.TIME:
			return "java.sql.Time";
		case Types.TIMESTAMP:
			return "java.sql.Timestamp";
		}
		return "String";
}
 
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);
}