List of usage examples for java.sql Types BLOB
int BLOB
To view the source code for java.sql Types BLOB.
Click Source Link
BLOB
. From source file:org.sakaiproject.mailarchive.impl.conversion.ExtractXMLToColumns.java
public Object getSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); String rv = null;//w w w . j ava 2 s . com switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { rv = new String(blob.getBytes(1L, (int) blob.length())); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: byte[] bytes = rs.getBytes(1); if (bytes != null) { rv = new String(bytes); } break; } // System.out.println("getSource(" + id + ") \n" + rv + "\n"); return rv; }
From source file:com.adaptris.core.services.jdbc.types.BlobColumnTranslatorTest.java
@Test public void testBlobToString() throws Exception { BlobColumnTranslator translator = new BlobColumnTranslator(); TestBlob blob = new TestBlob(); String myData = new String("SomeData"); blob.setBytes(0, myData.getBytes()); JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", blob, Types.BLOB); String translated = translator.translate(row, 0); assertEquals("SomeData", translated); }
From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobCollectionConversionHandler.java
public Object getSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); String rv = null;/*ww w .j a v a 2s.c o m*/ switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { rv = new String(blob.getBytes(1L, (int) blob.length())); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: byte[] bytes = rs.getBytes(1); if (bytes != null) { rv = new String(bytes); } break; } //System.out.println("getSource(" + id + ") \n" + rv + "\n"); return rv; }
From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java
public void testMapping() { Map<Integer, Class> testData = new HashMap<Integer, Class>(); testData.put(Types.CHAR, String.class); testData.put(Types.VARCHAR, String.class); testData.put(Types.LONGVARCHAR, String.class); testData.put(Types.NUMERIC, BigDecimal.class); testData.put(Types.DECIMAL, BigDecimal.class); testData.put(Types.BIT, Boolean.class); testData.put(Types.BOOLEAN, Boolean.class); testData.put(Types.TINYINT, Byte.class); testData.put(Types.SMALLINT, Short.class); testData.put(Types.INTEGER, Integer.class); testData.put(Types.BIGINT, Long.class); testData.put(Types.REAL, Float.class); testData.put(Types.FLOAT, Double.class); testData.put(Types.DOUBLE, Double.class); testData.put(Types.BINARY, byte[].class); testData.put(Types.VARBINARY, byte[].class); testData.put(Types.LONGVARBINARY, byte[].class); testData.put(Types.DATE, java.sql.Date.class); testData.put(Types.TIMESTAMP, java.sql.Timestamp.class); testData.put(Types.TIME, java.sql.Time.class); testData.put(Types.CLOB, java.sql.Clob.class); testData.put(Types.BLOB, java.sql.Blob.class); testData.put(Types.ARRAY, java.sql.Array.class); testData.put(Types.STRUCT, java.sql.Struct.class); testData.put(Types.REF, java.sql.Ref.class); testData.put(Types.DATALINK, java.net.URL.class); for (int type : testData.keySet()) { Class result = SQLTypeMapUtil.sqlTypeToClass(type, null); log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName()); assertEquals(testData.get(type), result); }//from w w w . j a v a 2 s . com assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String")); assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String")); }
From source file:au.com.ish.derbydump.derbydump.metadata.Column.java
/** * Get a string value for the value in this column in the datarow * //from w w w.ja va2s .c o m * @param dataRow The row which we are exporting * @return an SQL statement compliant string version of the value */ public String toString(ResultSet dataRow) throws SQLException { switch (getColumnDataType()) { case Types.BINARY: case Types.VARBINARY: case Types.BLOB: { Blob obj = dataRow.getBlob(columnName); return (obj == null) ? "NULL" : processBinaryData(obj); } case Types.CLOB: { Clob obj = dataRow.getClob(columnName); return (obj == null) ? "NULL" : processClobData(obj); } case Types.CHAR: case Types.LONGNVARCHAR: case Types.VARCHAR: { String obj = dataRow.getString(columnName); return (obj == null) ? "NULL" : processStringData(obj); } case Types.TIME: { Time obj = dataRow.getTime(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.DATE: { Date obj = dataRow.getDate(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.TIMESTAMP: { Timestamp obj = dataRow.getTimestamp(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.SMALLINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.BIGINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.INTEGER: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.NUMERIC: case Types.DECIMAL: { BigDecimal obj = dataRow.getBigDecimal(columnName); return (obj == null) ? "NULL" : String.valueOf(obj); } case Types.REAL: case Types.FLOAT: { Float obj = dataRow.getFloat(columnName); // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } case Types.DOUBLE: { Double obj = dataRow.getDouble(columnName); return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } default: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } } }
From source file:org.alfresco.repo.transfer.fsr.SchemaBootstrap.java
public void init() { // empty SerializableTypeHandler.setSerializableType(Types.BLOB); }
From source file:org.executequery.gui.resultset.TableCellData.java
public boolean isBlob() { return (dataType == Types.BLOB || dataType == Types.BINARY || dataType == Types.VARBINARY || dataType == Types.LONGVARBINARY); }
From source file:org.apache.lucene.store.jdbc.lock.PhantomReadLock.java
public boolean obtain() { try {//from ww w . ja v a2 s . c o m if (jdbcDirectory.getDialect().useExistsBeforeInsertLock()) { // there are databases where the fact that an exception was thrown // invalidates the connection. So first we check if it exists, and // then insert it. if (jdbcDirectory.fileExists(name)) { return false; } } jdbcDirectory.getJdbcTemplate().executeUpdate(jdbcDirectory.getTable().sqlInsert(), new JdbcTemplate.PrepateStatementAwareCallback() { public void fillPrepareStatement(PreparedStatement ps) throws Exception { ps.setFetchSize(1); ps.setString(1, name); ps.setNull(2, Types.BLOB); ps.setLong(3, 0); ps.setBoolean(4, false); } }); } catch (Exception e) { if (log.isTraceEnabled()) { log.trace("Obtain Lock exception (might be valid) [" + e.getMessage() + "]"); } return false; } return true; }
From source file:com.adaptris.core.services.jdbc.types.BlobColumnTranslatorTest.java
@Test public void testBlobToStringWithColumnName() throws Exception { BlobColumnTranslator translator = new BlobColumnTranslator(); TestBlob blob = new TestBlob(); String myData = new String("SomeData"); blob.setBytes(0, myData.getBytes()); JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", blob, Types.BLOB); String translated = translator.translate(row, "testField"); assertEquals("SomeData", translated); }
From source file:org.ambraproject.hibernate.OTMBlobType.java
public void nullSafeSet(PreparedStatement statement, java.lang.Object value, int index) throws HibernateException, SQLException { if (value == null) { statement.setNull(index, Types.BLOB); } else {/*from www. j ava2 s.co m*/ if (value instanceof org.topazproject.otm.Blob) { //TODO: I don't think the following line works statement.setBlob(index, ((org.topazproject.otm.Blob) value).getInputStream()); } else { throw new HibernateException("Object not of correct type: " + value.getClass().getName()); } } }