Java Code Examples for java.sql.Types#JAVA_OBJECT

The following examples show how to use java.sql.Types#JAVA_OBJECT . 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: PrestoResultSet.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Object getObject(int columnIndex)
        throws SQLException
{
    ColumnInfo columnInfo = columnInfo(columnIndex);
    switch (columnInfo.getColumnType()) {
        case Types.DATE:
            return getDate(columnIndex);
        case Types.TIME:
            return getTime(columnIndex);
        case Types.TIMESTAMP:
            return getTimestamp(columnIndex);
        case Types.ARRAY:
            return getArray(columnIndex);
        case Types.DECIMAL:
            return getBigDecimal(columnIndex);
        case Types.JAVA_OBJECT:
            if (columnInfo.getColumnTypeName().equalsIgnoreCase("interval year to month")) {
                return getIntervalYearMonth(columnIndex);
            }
            if (columnInfo.getColumnTypeName().equalsIgnoreCase("interval day to second")) {
                return getIntervalDayTime(columnIndex);
            }
    }
    return column(columnIndex);
}
 
Example 2
Source File: EthResultSetMetaData.java    From eth-jdbc-connector with Apache License 2.0 6 votes vote down vote up
@Override
public String getColumnTypeName(int column) throws SQLException {
    int sqlType = getColumnType(column);
    switch (sqlType) {
        case Types.INTEGER:
            return EthColumns.INTEGERTYPE;
        case Types.BIGINT:
            return EthColumns.BIGINTEGERTYPE;
        case Types.DOUBLE:
            return EthColumns.DOUBLETYPE;
        case Types.FLOAT:
            return EthColumns.FLOATTYPE;
        case Types.VARCHAR:
            return EthColumns.STRINGTYPE;
        case Types.JAVA_OBJECT:
            return EthColumns.OBJECTTYPE;
        default:
            return EthColumns.OBJECTTYPE;
    }
}
 
Example 3
Source File: DefaultJdbcSerDeser.java    From eagle with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param fieldValue
 * @param fieldType
 * @return
 */
@Override
public JdbcTypedValue toJdbcTypedValue(Object fieldValue, Class<?> fieldType, Qualifier qualifier) {
    int jdbcTypeCode = JdbcEntityDefinitionManager.getJdbcType(fieldType);
    if(Types.JAVA_OBJECT == jdbcTypeCode){
        byte[] bytes = qualifier.getSerDeser().serialize(fieldValue);
        return new JdbcTypedValue(bytes, JdbcConstants.DEFAULT_TYPE_FOR_COMPLEX_TYPE);
    } else {
        return new JdbcTypedValue(fieldValue, jdbcTypeCode);
    }
}
 
Example 4
Source File: JdbcThinUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param type a value from <code>java.sql.Types</code>.
 * @return {@code true} if type is plain and supported by thin JDBC driver.
 */
public static boolean isPlainJdbcType(int type) {
    return type != Types.ARRAY
        && type != Types.BLOB
        && type != Types.CLOB
        && type != Types.DATALINK
        && type != Types.JAVA_OBJECT
        && type != Types.NCHAR
        && type != Types.NVARCHAR
        && type != Types.LONGNVARCHAR
        && type != Types.REF
        && type != Types.ROWID
        && type != Types.SQLXML;
}
 
Example 5
Source File: DB2XMLWriter.java    From iaf with Apache License 2.0 5 votes vote down vote up
public static String getFieldType (int type) {
   switch (type) {
         case Types.INTEGER : return ("INTEGER");
         case Types.NUMERIC : return ("NUMERIC");
         case Types.CHAR :    return ("CHAR");
         case Types.DATE :    return ("DATE");
         case Types.TIMESTAMP : return ("TIMESTAMP");
         case Types.DOUBLE : return ("DOUBLE");
         case Types.FLOAT : return ("FLOAT");
         case Types.ARRAY : return ("ARRAY");
         case Types.BLOB : return ("BLOB");
         case Types.CLOB : return ("CLOB");
         case Types.DISTINCT : return ("DISTINCT");
         case Types.LONGVARBINARY : return ("LONGVARBINARY");
         case Types.VARBINARY : return ("VARBINARY");
         case Types.BINARY : return ("BINARY");
         case Types.REF : return ("REF");
         case Types.STRUCT : return ("STRUCT");
         case Types.JAVA_OBJECT  : return ("JAVA_OBJECT");
         case Types.VARCHAR  : return ("VARCHAR");
         case Types.TINYINT: return ("TINYINT");
         case Types.TIME: return ("TIME");
         case Types.REAL: return ("REAL");
         case Types.BOOLEAN: return ("BOOLEAN");
         case Types.BIT: return ("BIT");
         case Types.BIGINT: return ("BIGINT");
         case Types.SMALLINT: return ("SMALLINT");
}
   	return ("Unknown");
  }
 
Example 6
Source File: SQLUtil.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Converts sql type into string.
 * @param sqlType
 * @return
 */
public static String sqlType2str(int sqlType) {
    switch(sqlType) {
    case Types.BIT: return "BIT";
    case Types.TINYINT: return "TINYINT";
    case Types.SMALLINT: return "SMALLINT";
    case Types.INTEGER: return "INTEGER";
    case Types.BIGINT: return "BIGINT";
    case Types.FLOAT: return "FLOAT";
    case Types.REAL: return "REAL";
    case Types.DOUBLE: return "DOUBLE";
    case Types.NUMERIC: return "NUMERIC";
    case Types.DECIMAL: return "DECIMAL";
    case Types.CHAR: return "CHAR";
    case Types.VARCHAR: return "VARCHAR";
    case Types.LONGVARCHAR: return "LONGVARCHAR";
    case Types.DATE: return "DATE";
    case Types.TIME: return "TIME";
    case Types.TIMESTAMP: return "TIMESTAMP";
    case Types.BINARY: return "BINARY";
    case Types.VARBINARY: return "VARBINARY";
    case Types.LONGVARBINARY: return "LONGVARBINARY";
    case Types.NULL: return "NULL";
    case Types.OTHER: return "OTHER";
    case Types.JAVA_OBJECT: return "JAVA_OBJECT";
    case Types.DISTINCT: return "DISTINCT";
    case Types.STRUCT: return "STRUCT";
    case Types.ARRAY: return "ARRAY";
    case Types.BLOB: return "BLOB";
    case Types.CLOB: return "CLOB";
    case Types.REF: return "REF";
    case Types.DATALINK: return "DATALINK";
    case Types.BOOLEAN: return "BOOLEAN";
    default: return "<unknown sql type>";
    }
    
}
 
Example 7
Source File: ResultSetMetaDataImpl.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public int getColumnType(int column) throws SQLException {
  switch (getColumnTypeName(column)) {
    case "String":
      return Types.VARCHAR;
    case "Integer":
      return Types.INTEGER;
    case "Long":
      return Types.DOUBLE;
    case "Double":
      return Types.DOUBLE;
    default:
      return Types.JAVA_OBJECT;
  }
}
 
Example 8
Source File: JDBCDisplayUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static String getColumnDisplayString(ResultSet rs,
    ResultSetMetaData rsmd, int colNum, Vector nestedResults)
    throws SQLException {
  String s;
  switch (rsmd.getColumnType(colNum)) {
    case Types.JAVA_OBJECT:
    case Types.OTHER: {
      Object o = rs.getObject(colNum);
      if (o == null) {
        s = "NULL";
      }
      else if (o instanceof ResultSet && nestedResults != null) {
        s = LocalizedResource.getMessage("UT_Resul0_20",
            LocalizedResource.getNumber(nestedResults.size()));
        nestedResults.addElement(o);
      }
      else {
        try {
          s = rs.getString(colNum);
        } catch (SQLException se) {
          // oops, they don't support refetching the column
          s = o.toString();
        }
      }
      break;
    }
    default:
      s = LocalizedResource.getInstance()
          .getLocalizedString(rs, rsmd, colNum);
      break;
  }
  if (s == null) {
    s = "NULL";
  }
  return s;
}
 
Example 9
Source File: SectDBSynchronizer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Get the value of a column in current row in ResultSet as a string.
 * 
 * For binary data this returns hex-encoded string of the bytes.
 * 
 * For a java object this returns hex-encoded string of the serialized bytes
 * for the object.
 */
public static final String getColumnAsString(ResultSet rs, int columnIndex,
    int jdbcType) throws SQLException {
  byte[] bytes;
  switch (jdbcType) {
    case Types.BINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
      // convert to hex for binary columns
      bytes = rs.getBytes(columnIndex);
      if (bytes != null) {
        return toHexString(bytes, 0, bytes.length);
      }
      else {
        return null;
      }
    case Types.JAVA_OBJECT:
      // for java object type, serialize and then convert to hex
      Object v = rs.getObject(columnIndex);
      if (v != null) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        try {
          DataSerializer.writeObject(v, dos);
          dos.flush();
        } catch (IOException ioe) {
          // not expected to happen
          throw new SQLException(ioe.getMessage(), "XJ001", 0, ioe);
        }
        bytes = bos.toByteArray();
        return toHexString(bytes, 0, bytes.length);
      }
      else {
        return null;
      }
    default:
      return rs.getString(columnIndex);
  }
}
 
Example 10
Source File: JDBCDisplayUtil.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
static private void DisplayRow(PrintStream out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector nestedResults, Connection conn, int indentLevel,
							   int[] displayColumns, int[] displayColumnWidths)
	throws SQLException
{
	StringBuffer buf = new StringBuffer();
	buf.ensureCapacity(rowLen);

	int numCols = displayColumnWidths.length;
	int i;

	// get column header info
	// truncate it to the column display width
	// add a bar between each item.
	for (i=1; i <= numCols; i++){
		int colnum = displayColumns==null ? i : displayColumns[i-1];
		if (i>1)
			buf.append('|');

		String s;
		switch (rsmd.getColumnType(colnum)) {
		default:
			s = rs.getString(colnum);
			break;
		case Types.JAVA_OBJECT:
		case Types.OTHER:
		{
			Object o = rs.getObject(colnum);
			if (o == null) { s = "NULL"; }
			else if (o instanceof ResultSet && nestedResults != null)
			{
				s = "ResultSet #"+nestedResults.size();
				nestedResults.addElement(o);
			}
			else
			{
				try {
					s = rs.getString(colnum);
				} catch (SQLException se) {
					// oops, they don't support refetching the column
					s = o.toString();
				}
			}
		}
		break;
		}

		if (s==null) s = "NULL";

		int w = displayColumnWidths[i-1];
		if (s.length() < w) {
			StringBuilder fullS = new StringBuilder(s);
			fullS.ensureCapacity(w);
			for (int k=s.length(); k<w; k++)
				fullS.append(' ');
			s = fullS.toString();
		}
		else if (s.length() > w)
			// add the & marker to know it got cut off
			s = s.substring(0,w-1)+"&";

		buf.append(s);
	}
	indentedPrintLine( out, indentLevel, buf);

}
 
Example 11
Source File: ResultSetToKVStoreSerializer.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public IKVStore serializeRow(final ResultSet values, final String[] columnNames, final int[] columnTypes) throws SQLException, ResultSetSerializerException {
	KVStore store = new KVStore();

	for (int i = 0; i < columnNames.length; i++) {
		String fieldName = columnNames[i];

		switch (columnTypes[i]) {
		case Types.INTEGER:
			store.put(fieldName, values.getInt(i + 1));
			break;
		case Types.BIGINT:
			store.put(fieldName, values.getLong(i + 1));
			break;
		case Types.DECIMAL:
		case Types.NUMERIC:
			store.put(fieldName, values.getBigDecimal(i + 1));
			break;
		case Types.FLOAT:
		case Types.REAL:
		case Types.DOUBLE:
			store.put(fieldName, values.getDouble(i + 1));
			break;
		case Types.NVARCHAR:
		case Types.VARCHAR:
		case Types.LONGNVARCHAR:
		case Types.LONGVARCHAR:
			store.put(fieldName, values.getString(i + 1));
			break;
		case Types.BOOLEAN:
		case Types.BIT:
			store.put(fieldName, values.getBoolean(i + 1));
			break;
		case Types.BINARY:
		case Types.VARBINARY:
		case Types.LONGVARBINARY:
			store.put(fieldName, values.getByte(i + 1));
			break;
		case Types.TINYINT:
		case Types.SMALLINT:
			store.put(fieldName, values.getShort(i + 1));
			break;
		case Types.DATE:
			store.put(fieldName, values.getDate(i + 1));
			break;
		case Types.TIMESTAMP:
			store.put(fieldName, values.getTime(i + 1));
			break;

		case Types.BLOB:
			store.put(fieldName, values.getBlob(i));
			break;

		case Types.CLOB:
			store.put(fieldName, values.getClob(i));
			break;

		case Types.ARRAY:
			throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type ARRAY");

		case Types.STRUCT:
			throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type STRUCT");

		case Types.DISTINCT:
			throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type DISTINCT");

		case Types.REF:
			throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type REF");

		case Types.JAVA_OBJECT:
		default:
			store.put(fieldName, values.getObject(i + 1));
			break;
		}

		if (values.wasNull()) {
			store.put(fieldName, null);
		}
	}
	return store;
}
 
Example 12
Source File: SakaiReport.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private String getColumnValue(ResultSet rs, int colType, int colIndex)
        throws SQLException, IOException {
    String value = "";
    switch (colType) {
        case Types.BIT:
        case Types.JAVA_OBJECT:
            value = handleObject(rs.getObject(colIndex));
            break;
        case Types.BOOLEAN:
            boolean b = rs.getBoolean(colIndex);
            value = Boolean.valueOf(b).toString();
            break;
        case NCLOB: // todo : use rs.getNClob
        case Types.CLOB:
            Clob c = rs.getClob(colIndex);
            if (c != null) {
                value = read(c);
            }
            break;
        case Types.BIGINT:
            value = handleLong(rs, colIndex);
            break;
        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.FLOAT:
        case Types.REAL:
        case Types.NUMERIC:
            value = handleBigDecimal(rs.getBigDecimal(colIndex));
            break;
        case Types.INTEGER:
        case Types.TINYINT:
        case Types.SMALLINT:
            value = handleInteger(rs, colIndex);
            break;
        case Types.DATE:
            value = handleDate(rs, colIndex);
            break;
        case Types.TIME:
            value = handleTime(rs.getTime(colIndex));
            break;
        case Types.TIMESTAMP:
            value = handleTimestamp(rs.getTimestamp(colIndex));
            break;
        case NVARCHAR: // todo : use rs.getNString
        case NCHAR: // todo : use rs.getNString
        case LONGNVARCHAR: // todo : use rs.getNString
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.CHAR:
            value = rs.getString(colIndex);
            break;
        case Types.VARBINARY:
        case Types.BINARY:
            value = handleRaw(rs.getBytes(colIndex));
            break;
        default:
            value = "";
    }


    if (value == null) {
        value = "";
    }

    return value;

}
 
Example 13
Source File: CallableStatement.java    From r-course with MIT License 4 votes vote down vote up
private void setInOutParamsOnServer() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.paramInfo.numParameters > 0) {
            for (Iterator<CallableStatementParam> paramIter = this.paramInfo.iterator(); paramIter.hasNext();) {

                CallableStatementParam inParamInfo = paramIter.next();

                //Fix for 5.5+
                if (inParamInfo.isOut && inParamInfo.isIn) {
                    if ((inParamInfo.paramName == null) && (hasParametersView())) {
                        inParamInfo.paramName = "nullnp" + inParamInfo.index;
                    }

                    String inOutParameterName = mangleParameterName(inParamInfo.paramName);
                    StringBuilder queryBuf = new StringBuilder(4 + inOutParameterName.length() + 1 + 1);
                    queryBuf.append("SET ");
                    queryBuf.append(inOutParameterName);
                    queryBuf.append("=?");

                    PreparedStatement setPstmt = null;

                    try {
                        setPstmt = ((Wrapper) this.connection.clientPrepareStatement(queryBuf.toString())).unwrap(PreparedStatement.class);

                        if (this.isNull[inParamInfo.index]) {
                            setPstmt.setBytesNoEscapeNoQuotes(1, "NULL".getBytes());

                        } else {
                            byte[] parameterAsBytes = getBytesRepresentation(inParamInfo.index);

                            if (parameterAsBytes != null) {
                                if (parameterAsBytes.length > 8 && parameterAsBytes[0] == '_' && parameterAsBytes[1] == 'b' && parameterAsBytes[2] == 'i'
                                        && parameterAsBytes[3] == 'n' && parameterAsBytes[4] == 'a' && parameterAsBytes[5] == 'r'
                                        && parameterAsBytes[6] == 'y' && parameterAsBytes[7] == '\'') {
                                    setPstmt.setBytesNoEscapeNoQuotes(1, parameterAsBytes);
                                } else {
                                    int sqlType = inParamInfo.desiredJdbcType;

                                    switch (sqlType) {
                                        case Types.BIT:
                                        case Types.BINARY:
                                        case Types.BLOB:
                                        case Types.JAVA_OBJECT:
                                        case Types.LONGVARBINARY:
                                        case Types.VARBINARY:
                                            setPstmt.setBytes(1, parameterAsBytes);
                                            break;
                                        default:
                                            // the inherited PreparedStatement methods have already escaped and quoted these parameters
                                            setPstmt.setBytesNoEscape(1, parameterAsBytes);
                                    }
                                }
                            } else {
                                setPstmt.setNull(1, Types.NULL);
                            }
                        }

                        setPstmt.executeUpdate();
                    } finally {
                        if (setPstmt != null) {
                            setPstmt.close();
                        }
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: Cursor.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public final Object getObject(int column) {
      if (isNull(column))
        return null;
        switch (jdbcTypes_[column - 1]) {
        case Types.BOOLEAN:
            return get_BOOLEAN(column);
        case Types.SMALLINT:
            // See Table 4 in JDBC 1 spec (pg. 932 in jdbc book)
            // @AGG since this is not JDBC, just return as a short
            //return Integer.valueOf(get_SMALLINT(column));
            return get_SMALLINT(column);
        case Types.INTEGER:
            return get_INTEGER(column);
        case Types.BIGINT:
            return get_BIGINT(column);
        case Types.REAL:
            return get_FLOAT(column);
        case Types.DOUBLE:
            return get_DOUBLE(column);
        case Types.DECIMAL:
            return get_DECIMAL(column);
        case Types.DATE:
            return get_DATE(column);
        case Types.TIME:
            return get_TIME(column);
        case Types.TIMESTAMP:
            return get_TIMESTAMP(column);
        case Types.CHAR:
            return get_CHAR(column);
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return get_VARCHAR(column);
        case ClientTypes.BINARY:
            return get_CHAR_FOR_BIT_DATA(column);
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return get_VARCHAR_FOR_BIT_DATA(column);
        case Types.JAVA_OBJECT:
            return get_UDT( column );
        case Types.ROWID:
            return get_ROWID(column);
//        case Types.BLOB:
//            return getBlobColumn_(column, agent_, true);
//        case Types.CLOB:
//            return getClobColumn_(column, agent_, true);
        default:
            throw coercionError("Object type: ", column );
        }
    }
 
Example 15
Source File: JtdsResultSet.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void updateObject(int columnIndex, Object x) throws SQLException {
    checkOpen();
    int length = 0;
    int jdbcType = Types.VARCHAR; // Use for NULL values

    if (x != null) {
        // Need to do some conversion and testing here
        jdbcType = Support.getJdbcType(x);
        if (x instanceof BigDecimal) {
            int prec = getConnection().getMaxPrecision();
            x = Support.normalizeBigDecimal((BigDecimal)x, prec);
        } else if (x instanceof Blob) {
            Blob blob = (Blob) x;
            x = blob.getBinaryStream();
            length = (int) blob.length();
        } else if (x instanceof Clob) {
            Clob clob = (Clob) x;
            x = clob.getCharacterStream();
            length = (int) clob.length();
        } else if (x instanceof String) {
            length = ((String)x).length();
        } else if (x instanceof byte[]) {
            length = ((byte[])x).length;
        }
        if (jdbcType == Types.JAVA_OBJECT) {
            // Unsupported class of object
            if (columnIndex < 1 || columnIndex > columnCount) {
                throw new SQLException(Messages.get("error.resultset.colindex",
                        Integer.toString(columnIndex)),
                        "07009");
            }
            ColInfo ci = columns[columnIndex-1];
            throw new SQLException(
                    Messages.get("error.convert.badtypes",
                            x.getClass().getName(),
                            Support.getJdbcTypeName(ci.jdbcType)), "22005");
        }
    }

    setColValue(columnIndex, jdbcType, x, length);
}
 
Example 16
Source File: JDBCUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Get the SQLType for the given java.sql.Type type.
 *
 * @param type the java.sql.Type type specifier
 * @return SQLType.the SQLType for this java.sql.Type, or null if it's not recognized
 */
public static SQLType getSQLType(int type) {
    switch (type) {
        case Types.BIT: return SQLType.BIT;
        case Types.TINYINT: return SQLType.TINYINT;
        case Types.SMALLINT: return SQLType.SMALLINT;
        case Types.INTEGER: return SQLType.INTEGER;
        case Types.BIGINT: return SQLType.BIGINT;
        case Types.FLOAT: return SQLType.FLOAT;
        case Types.REAL: return SQLType.REAL;
        case Types.DOUBLE: return SQLType.DOUBLE;
        case Types.NUMERIC: return SQLType.NUMERIC;
        case Types.DECIMAL: return SQLType.DECIMAL;
        case Types.CHAR: return SQLType.CHAR;
        case Types.VARCHAR: return SQLType.VARCHAR;
        case Types.LONGVARCHAR: return SQLType.LONGVARCHAR;
        case Types.DATE: return SQLType.DATE;
        case Types.TIME: return SQLType.TIME;
        case Types.TIMESTAMP: return SQLType.TIMESTAMP;
        case Types.BINARY: return SQLType.BINARY;
        case Types.VARBINARY: return SQLType.VARBINARY;
        case Types.LONGVARBINARY: return SQLType.LONGVARBINARY;
        case Types.NULL: return SQLType.NULL;
        case Types.OTHER: return SQLType.OTHER;
        case Types.JAVA_OBJECT: return SQLType.JAVA_OBJECT;
        case Types.DISTINCT: return SQLType.DISTINCT;
        case Types.STRUCT: return SQLType.STRUCT;
        case Types.ARRAY: return SQLType.ARRAY;
        case Types.BLOB: return SQLType.BLOB;
        case Types.CLOB: return SQLType.CLOB;
        case Types.REF: return SQLType.REF;
        case Types.DATALINK: return SQLType.DATALINK;
        case Types.BOOLEAN: return SQLType.BOOLEAN;
        case Types.LONGNVARCHAR: return SQLType.LONGVARCHAR;
        case Types.NCHAR: return SQLType.CHAR;
        case Types.NCLOB: return SQLType.CLOB;
        case Types.NVARCHAR: return SQLType.VARCHAR;
        case Types.SQLXML: return SQLType.SQLXML;
        case Types.ROWID: return SQLType.ROWID;
        default:
            Logger.getLogger(JDBCUtils.class.getName()).log(Level.WARNING, "Unknown JDBC column type: " + type + ". Returns null.");
            return null;
    }
}
 
Example 17
Source File: TypeMapper.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static Class mapSQLType( final int t ) {
  switch ( t ) {
    case Types.ARRAY:
      return Object[].class;
    case Types.BIGINT:
      return Long.class;
    case Types.BINARY:
      return byteArrayClass;
    case Types.BIT:
      return Boolean.class;
    case Types.BLOB:
      return Blob.class;
    case Types.BOOLEAN: // Types.BOOLEAN was not part of JDK1.2.2
      return Boolean.class;
    case Types.CHAR:
      return String.class;
    case Types.CLOB:
      return Clob.class;
    case Types.DATALINK: // Types.DATALINK was not part of JDK 1.2.2
      return URL.class;
    case Types.DATE:
      return java.sql.Date.class;
    case Types.DECIMAL:
      return java.math.BigDecimal.class;
    case Types.DISTINCT:
      return Object.class;
    case Types.DOUBLE:
      return Double.class;
    case Types.FLOAT:
      return Double.class;
    case Types.INTEGER:
      return Integer.class;
    case Types.JAVA_OBJECT:
      return Object.class;
    case Types.LONGVARBINARY:
      return byteArrayClass;
    case Types.LONGVARCHAR:
      return String.class;
    case Types.NCLOB:
      return NClob.class;
    case Types.NULL:
      return Object.class;
    case Types.NUMERIC:
      return java.math.BigDecimal.class;
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
      return String.class;
    case Types.OTHER:
      return Object.class;
    case Types.REAL:
      return Float.class;
    case Types.REF:
      return Ref.class;
    case Types.ROWID:
      return RowId.class;
    case Types.SMALLINT:
      return Short.class;
    case Types.STRUCT:
      return Struct.class;
    case Types.SQLXML:
      return SQLXML.class;
    case Types.TIME:
      return Time.class;
    case Types.TIMESTAMP:
      return Timestamp.class;
    case Types.TINYINT:
      return Byte.class;
    case Types.VARBINARY:
      return byteArrayClass;
    case Types.VARCHAR:
      return String.class;
    default:
      return Object.class;
  }
}
 
Example 18
Source File: ParseUtil.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public static Field generateField(
    String column,
    String columnValue,
    int columnType,
    DateTimeColumnHandler dateTimeColumnHandler
) throws StageException {
  Field field;
  // 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 (columnType) {
    case Types.BIGINT:
      field = Field.create(Field.Type.LONG, columnValue);
      break;
    case Types.BINARY:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
      field = Field.create(Field.Type.BYTE_ARRAY, RawTypeHandler.parseRaw(column, columnValue, columnType));
      break;
    case Types.BIT:
    case Types.BOOLEAN:
      field = Field.create(Field.Type.BOOLEAN, columnValue);
      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, columnValue);
      break;
    case Types.DECIMAL:
    case Types.NUMERIC:
      field = Field.create(Field.Type.DECIMAL, columnValue);
      break;
    case Types.DOUBLE:
      field = Field.create(Field.Type.DOUBLE, columnValue);
      break;
    case Types.FLOAT:
    case Types.REAL:
      field = Field.create(Field.Type.FLOAT, columnValue);
      break;
    case Types.INTEGER:
      field = Field.create(Field.Type.INTEGER, columnValue);
      break;
    case Types.SMALLINT:
    case Types.TINYINT:
      field = Field.create(Field.Type.SHORT, columnValue);
      break;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
      field = dateTimeColumnHandler.getDateTimeStampField(column, columnValue, columnType);
      break;
    case Types.TIMESTAMP_WITH_TIMEZONE:
    case TIMESTAMP_TZ_TYPE:
      field = dateTimeColumnHandler.getTimestampWithTimezoneField(columnValue);
      break;
    case TIMESTAMP_LTZ_TYPE:
      field = dateTimeColumnHandler.getTimestampWithLocalTimezone(columnValue);
      break;
    case Types.ROWID:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.BLOB:
    case Types.ARRAY:
    case Types.DATALINK:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.NULL:
    case Types.OTHER:
    case Types.REF:
    case Types.REF_CURSOR:
    case Types.SQLXML:
    case Types.STRUCT:
    case Types.TIME_WITH_TIMEZONE:
    default:
      throw new UnsupportedFieldTypeException(column, columnValue, columnType);
  }
  return field;
}
 
Example 19
Source File: TeradataDialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String getSelectClauseNullString(int sqlType) {
	String v = "null";

	switch ( sqlType ) {
		case Types.BIT:
		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:
			v = "cast(null as decimal)";
			break;
		case Types.CHAR:
		case Types.VARCHAR:
		case Types.LONGVARCHAR:
			v = "cast(null as varchar(255))";
			break;
		case Types.DATE:
		case Types.TIME:
		case Types.TIMESTAMP:
			v = "cast(null as timestamp)";
			break;
		case Types.BINARY:
		case Types.VARBINARY:
		case Types.LONGVARBINARY:
		case Types.NULL:
		case Types.OTHER:
		case Types.JAVA_OBJECT:
		case Types.DISTINCT:
		case Types.STRUCT:
		case Types.ARRAY:
		case Types.BLOB:
		case Types.CLOB:
		case Types.REF:
		case Types.DATALINK:
		case Types.BOOLEAN:
			break;
	}
	return v;
}
 
Example 20
Source File: ESArray.java    From sql4es with Apache License 2.0 4 votes vote down vote up
@Override
public int getBaseType() throws SQLException {
	if(array != null && array.size() > 0) return Heading.getTypeIdForObject( array.get(0) );
	else return Types.JAVA_OBJECT;
}