List of usage examples for java.sql Types BINARY
int BINARY
To view the source code for java.sql Types BINARY.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BINARY
.
From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java
public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException { String value = ""; switch (colType) { case Types.BIT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); }//from w w w . j a v a 2 s. c o m break; case Types.BOOLEAN: if (jdbcObject != null) { value = new Boolean(jdbcObject.toString()).toString(); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.CLOB: if (jdbcObject != null) { try { value = read((Clob) jdbcObject); } catch (SQLException sqle) { value = ""; } catch (IOException ioe) { value = ""; } } break; case Types.ARRAY: try { ResultSet rs = ((Array) jdbcObject).getResultSet(); int arrayType = ((Array) jdbcObject).getBaseType(); boolean isNotNew = false; while (rs.next()) { String current = formatJDBCObject(rs.getObject(2), arrayType); if ("".equals(current.trim()) == false) { if (isNotNew) { value = value + ","; } else { isNotNew = !isNotNew; } value = value + current; } } if ("".equals(value) == false) { value = "{" + value + "}"; } } catch (SQLException sqle) { value = ""; } break; case Types.JAVA_OBJECT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); } break; case Types.DATE: if (jdbcObject != null) { value = formatter.formatDate(jdbcObject); } break; case Types.TIME: if (jdbcObject != null) { value = ((Time) jdbcObject).toString(); } break; case Types.TIMESTAMP: if (jdbcObject != null) { value = formatter.formatTimestamp(jdbcObject); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: if (jdbcObject != null) { value = jdbcObject.toString(); } else { value = "NULL"; } break; case Types.BINARY: value = new String((byte[]) jdbcObject); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java
protected void registerDefaultJavaTypes() { registerJavaType(Types.BIT, Boolean.class.getName()); registerJavaType(Types.TINYINT, Byte.class.getName()); registerJavaType(Types.SMALLINT, Short.class.getName()); // registerJavaType(Types.CHAR, Character.class.getName()); registerJavaType(Types.CHAR, String.class.getName()); registerJavaType(Types.VARCHAR, String.class.getName()); registerJavaType(Types.DATE, Date.class.getName()); registerJavaType(Types.TIME, Time.class.getName()); registerJavaType(Types.TIMESTAMP, Timestamp.class.getName()); registerJavaType(Types.DOUBLE, Double.class.getName()); registerJavaType(Types.FLOAT, Float.class.getName()); registerJavaType(Types.INTEGER, Integer.class.getName()); registerJavaType(Types.BIGINT, BigInteger.class.getName()); // registerJavaType(Types.BIGINT, Long.class.getName()); registerJavaType(Types.NUMERIC, BigDecimal.class.getName()); registerJavaType(Types.DECIMAL, BigDecimal.class.getName()); registerJavaType(Types.BINARY, byte[].class.getName()); registerJavaType(Types.VARBINARY, byte[].class.getName()); registerJavaType(Types.BLOB, String.class.getName()); registerJavaType(Types.CLOB, String.class.getName()); registerJavaType(Types.REAL, String.class.getName()); registerJavaType(Types.OTHER, Object.class.getName()); }
From source file:org.jumpmind.db.platform.mssql.MsSqlDdlReader.java
protected Integer mapUnknownJdbcTypeForColumn(Map<String, Object> values) { String typeName = (String) values.get("TYPE_NAME"); int size = -1; String columnSize = (String) values.get("COLUMN_SIZE"); if (isNotBlank(columnSize)) { size = Integer.parseInt(columnSize); }/*w w w . j av a 2 s. com*/ if (typeName != null && typeName.toLowerCase().startsWith("text")) { return Types.LONGVARCHAR; } else if (typeName != null && typeName.toLowerCase().startsWith("ntext")) { return Types.CLOB; } else if (typeName != null && typeName.toUpperCase().contains(TypeMap.GEOMETRY)) { return Types.VARCHAR; } else if (typeName != null && typeName.toUpperCase().contains("VARCHAR") && size > 8000) { return Types.LONGVARCHAR; } else if (typeName != null && typeName.toUpperCase().contains("NVARCHAR") && size > 8000) { return Types.LONGNVARCHAR; } else if (typeName != null && typeName.toUpperCase().equals("SQL_VARIANT")) { return Types.BINARY; } else { return super.mapUnknownJdbcTypeForColumn(values); } }
From source file:org.sakaiproject.mailarchive.impl.conversion.ExtractXMLToColumns.java
public Object getValidateSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); byte[] rv = null; switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { rv = blob.getBytes(1L, (int) blob.length()); } else {/*from w ww .j a v a2 s . c om*/ System.out.println("getValidateSource(" + id + ") blob == null"); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()).getBytes(); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: rv = rs.getString(1).getBytes(); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: rv = rs.getBytes(1); break; } // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n"); return rv; }
From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java
private static Class<?> getJavaType(int sqltype, int precision, int scale) { switch (sqltype) { case Types.BIGINT: return Long.class; case Types.BIT: return Boolean.class; case Types.BOOLEAN: return Boolean.class; case Types.CHAR: return String.class; case Types.DECIMAL: return getNumericType(precision, scale); case Types.DOUBLE: return Double.class; case Types.FLOAT: return Double.class; case Types.INTEGER: return Integer.class; case Types.LONGVARCHAR: return String.class; case Types.NUMERIC: return getNumericType(precision, scale); case Types.REAL: return Float.class; case Types.SMALLINT: return Short.class; case Types.DATE: return java.sql.Timestamp.class; case Types.TIME: return java.sql.Time.class; case Types.TIMESTAMP: return java.sql.Timestamp.class; case Types.TINYINT: return Byte.class; case Types.VARCHAR: return String.class; case Types.BLOB: return byte[].class; case Types.LONGVARBINARY: return byte[].class; case Types.CLOB: return String.class; case Types.BINARY: return byte[].class; case Types.VARBINARY: return byte[].class; case Types.NVARCHAR: return String.class; case Types.NCHAR: return String.class; case Types.LONGNVARCHAR: return String.class; case -155://from www .j a v a 2 s.c o m return java.sql.Timestamp.class; default: return Object.class; } }
From source file:org.apache.syncope.core.util.ContentExporter.java
private String getValues(final ResultSet rs, final String columnName, final Integer columnType) throws SQLException { String res = null;//from w w w . j av a 2 s . co m try { switch (columnType) { case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: final InputStream is = rs.getBinaryStream(columnName); if (is != null) { res = new String(Hex.encode(IOUtils.toByteArray(is))); } break; case Types.BLOB: final Blob blob = rs.getBlob(columnName); if (blob != null) { res = new String(Hex.encode(IOUtils.toByteArray(blob.getBinaryStream()))); } break; case Types.BIT: case Types.BOOLEAN: if (rs.getBoolean(columnName)) { res = "1"; } else { res = "0"; } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnName); if (timestamp != null) { res = DataFormat.format(new Date(timestamp.getTime())); } break; default: res = rs.getString(columnName); } } catch (IOException e) { LOG.error("Error retrieving hexadecimal string", e); } return res; }
From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobCollectionConversionHandler.java
public Object getValidateSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); byte[] rv = null; switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { //System.out.println("getValidateSource(" + id + ") blob == " + blob + " blob.length == " + blob.length()); rv = blob.getBytes(1L, (int) blob.length()); } else {// w w w. j a v a 2s .com System.out.println("getValidateSource(" + id + ") blob is null"); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()).getBytes(); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: rv = rs.getString(1).getBytes(); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: rv = rs.getBytes(1); break; } //System.out.println("getValidateSource(" + id + ") \n" + rv + "\n"); return rv; }
From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobResourcesConversionHandler.java
public Object getValidateSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); byte[] rv = null; switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { //System.out.println("getValidateSource(" + id + ") blob == " + blob + " blob.length == " + blob.length()); rv = blob.getBytes(1L, (int) blob.length()); } else {//from w w w . j a v a2 s .c o m System.out.println("getValidateSource(" + id + ") blob is null"); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()).getBytes(); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: rv = rs.getString(1).getBytes(); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: rv = rs.getBytes(1); break; } // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n"); return rv; //return rs.getBytes(1); }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private void initDialect(DatabaseIdiom idiom) { databaseIdiom = idiom;/*from w w w . j a v a 2 s . c om*/ try { addTranslation("bigint", idiom.getTypeName(Types.BIGINT)); addTranslation("binary", idiom.getTypeName(Types.BINARY)); addTranslation("bit", idiom.getTypeName(Types.BIT)); addTranslation("blob", idiom.getTypeName(Types.BLOB)); addTranslation("boolean", idiom.getTypeName(Types.BOOLEAN)); addTranslation("char", idiom.getTypeName(Types.CHAR)); addTranslation("clob", idiom.getTypeName(Types.CLOB)); addTranslation("date", idiom.getTypeName(Types.DATE)); addTranslation("decimal", idiom.getTypeName(Types.DECIMAL)); addTranslation("double", idiom.getTypeName(Types.DOUBLE)); addTranslation("float", idiom.getTypeName(Types.FLOAT)); addTranslation("integer", idiom.getTypeName(Types.INTEGER)); addTranslation("longnvarchar", idiom.getTypeName(Types.LONGNVARCHAR)); addTranslation("longvarbinary", idiom.getTypeName(Types.LONGVARBINARY)); addTranslation("longvarchar", idiom.getTypeName(Types.LONGVARCHAR)); addTranslation("nchar", idiom.getTypeName(Types.NCHAR)); addTranslation("nclob", idiom.getTypeName(Types.NCLOB)); addTranslation("numeric", idiom.getTypeName(Types.NUMERIC)); addTranslation("nvarchar", idiom.getTypeName(Types.NVARCHAR)); addTranslation("real", idiom.getTypeName(Types.REAL)); addTranslation("smallint", idiom.getTypeName(Types.SMALLINT)); addTranslation("time", idiom.getTypeName(Types.TIME)); addTranslation("timestamp", idiom.getTypeName(Types.TIMESTAMP)); addTranslation("tinyint", idiom.getTypeName(Types.TINYINT)); addTranslation("varbinary", idiom.getTypeName(Types.VARBINARY)); databaseIdiom.initDialect(translations, workarounds); // Ignore autogenerated ID's addWorkaround("generated always as identity", ""); } catch (Exception e) { throw new IllegalArgumentException(e); } }