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: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 w w w .jav a2 s . co m*/ return java.sql.Timestamp.class; default: return Object.class; } }
From source file:org.jumpmind.db.platform.postgresql.PostgreSqlDatabasePlatform.java
@Override public Object[] getObjectValues(BinaryEncoding encoding, String[] values, Column[] orderedMetaData, boolean useVariableDates, boolean fitToColumn) { Object[] objectValues = super.getObjectValues(encoding, values, orderedMetaData, useVariableDates, fitToColumn);// w ww . j a v a2 s .co m for (int i = 0; i < orderedMetaData.length; i++) { if (orderedMetaData[i] != null && orderedMetaData[i].getMappedTypeCode() == Types.BLOB && objectValues[i] != null) { try { objectValues[i] = new SerialBlob((byte[]) objectValues[i]); } catch (Exception e) { throw new RuntimeException(e); } } } return objectValues; }
From source file:com.sr.model.dao.IMahasiswaDAOImpl.java
@Override public boolean insertBiodata(Mahasiswa mhs, AkademikSR aka, FileItem foto, List<Prestasi> prestasi) { try {//w w w .j a va 2 s .c o m LobHandler lobHandler = new DefaultLobHandler(); getJdbcTemplate().update(INSERT_BIODATA, new Object[] { mhs.getNamaMhs(), mhs.getTempat_lahir(), mhs.getTanggal_lahir(), mhs.getAgama(), mhs.getKelamin(), mhs.getAlamat_asal(), mhs.getKab_kota_asal(), mhs.getProv_asal(), mhs.getNo_hp_mhs(), mhs.getNama_ayah(), mhs.getNama_ibu(), mhs.getPendidikan_ayah(), mhs.getPendidikan_ibu(), mhs.getPekerjaan_ayah(), mhs.getPekerjaan_ibu(), mhs.getPendapatan_ortu(), mhs.getNo_tel_ortu(), mhs.getNo_hp_ortu(), mhs.getAlamat_keluarga(), mhs.getNo_tel_keluarga(), mhs.getNo_hp_keluarga(), new SqlLobValue(foto.getInputStream(), (int) foto.getSize(), lobHandler), mhs.getNim() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); getJdbcTemplate().update(INSERT_AKADEMIK, new Object[] { aka.getProdi(), aka.getIpk_masuk(), aka.getSemester(), aka.getRapor_smu(), aka.getJurusan(), aka.getFakultas(), aka.getNim() }, new int[] { Types.VARCHAR, Types.DECIMAL, Types.NUMERIC, Types.DECIMAL, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); for (Prestasi pres : prestasi) { getJdbcTemplate().update(INSERT_PRESTASI, new Object[] { pres.getNo_sertifikat(), pres.getNim(), pres.getNama_prestasi(), pres.getJenis_prestasi() }); } return true; } catch (DataAccessException da) { System.out.println("DataAccessException" + da.getMessage()); } catch (FileNotFoundException ex) { System.out.println("FileNotFoundException " + ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } return false; }
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java
private MapSqlParameterSource getCompleteParameters() { MapSqlParameterSource tcParameters = getInitialDataParameters(); tcParameters.addValues(getGuidParameter().getValues()); tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp()); int warningTime = testSuite.getWarningTime(); tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null); int criticalTime = testSuite.getCriticalTime(); tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null); tcParameters.addValue("duration", testSuite.getDuration()); //try to save the screenshot try {/*from w w w .j av a2 s. c o m*/ if (testSuite.getScreenShotPath() != null) { final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath()); final int length = (int) testSuite.getScreenShotPath().toFile().length(); tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB); } } catch (IOException e) { throw new RuntimeException(e); } tcParameters.addValue("msg", testSuite.getExceptionMessages()); return tcParameters; }
From source file:org.apache.camel.processor.aggregate.jdbc.OptimisticLockingJdbcAggregationRepository.java
@Override public Exchange add(CamelContext camelContext, String key, Exchange exchange) { return getTransactionTemplate().execute(new TransactionCallback<Exchange>() { @Override/*from w ww.j av a2 s. co m*/ public Exchange doInTransaction(TransactionStatus status) { Exchange result = get(camelContext, key); try { log.debug(String.format("Adding exchange with key: [%s]", key)); byte[] marshalledExchange = getCodec().marshallExchange(camelContext, exchange, true); boolean present = getJdbcTemplate().queryForObject( String.format("SELECT COUNT(*) FROM %1$s WHERE %2$s=?", getRepositoryName(), ID_KEY), new Object[] { key }, new int[] { Types.VARCHAR }, Integer.class) != 0; if (present) { long version = exchange.getProperty(VERSION_EXCHANGE_PROPERTY, Long.class); log.debug(String.format("Updating record with key: [%s] and version: [%s].", key, version)); int affectedRows = getJdbcTemplate().update( String.format("UPDATE %1$s SET %2$s=?, %3$s=? WHERE %4$s=? AND %3$s=?", getRepositoryName(), EXCHANGE_KEY, VERSION_KEY, ID_KEY), new Object[] { new SqlLobValue(marshalledExchange, getLobHandler()), version + 1, key, version }, new int[] { Types.BLOB, Types.BIGINT, Types.VARCHAR, Types.BIGINT }); if (affectedRows < 1) { throw new RuntimeException(String.format( "Error updating record with key: [%s] and version: [%s]. Stale version...", key, version)); } } else { log.debug(String.format("Inserting record with key: [%s].", key)); getJdbcTemplate().update( String.format("INSERT INTO %1$s (%2$s, %3$s, %4$s) VALUES (?, ?, ?)", getRepositoryName(), ID_KEY, EXCHANGE_KEY, VERSION_KEY), new Object[] { key, new SqlLobValue(marshalledExchange, getLobHandler()), 1L }, new int[] { Types.VARCHAR, Types.BLOB, Types.BIGINT }); } } catch (Exception e) { throw new RuntimeException(String.format("Error adding to repository [%s] with key [%s].", getRepositoryName(), key), e); } return result; } }); }
From source file:org.easyrec.store.dao.plugin.impl.LogEntryDAOMysqlImpl.java
protected LogEntryDAOMysqlImpl(DataSource dataSource, SqlScriptService sqlScriptService, PluginRegistry pluginRegistry) { super(sqlScriptService); setDataSource(dataSource);//from ww w . j a va 2s .c o m startEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, " + "configuration) VALUES (?, ?, ?, ?, ?, ?)", new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB }); startEntry.compile(); endEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, configuration, " + "endDate, statistics) VALUES (?, ?, ?, ?, ?, ?, ?, ?) " + "ON DUPLICATE KEY UPDATE endDate = ?, statistics = ?", new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB, Types.TIMESTAMP, Types.BLOB, Types.TIMESTAMP, Types.BLOB }); endEntry.compile(); endAllEntries = new SqlUpdate(dataSource, "UPDATE plugin_log SET endDate = ?, statistics = ? WHERE endDate IS NULL", new int[] { Types.TIMESTAMP, Types.BLOB }); endAllEntries.compile(); getRunningTenants = new MappingSqlQuery<Integer>(dataSource, "SELECT tenantId FROM plugin_log WHERE endDate IS NULL") { @Override protected Integer mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getInt("tenantId"); } }; getRunningTenants.compile(); getLogEntries = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log ORDER BY endDate DESC, id DESC LIMIT ?, ?"); getLogEntries.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntries.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntries.compile(); getLogEntriesForTenant = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE tenantId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesForTenant.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getLogEntriesForTenant.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesForTenant.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesForTenant.compile(); getLogEntriesWithAssocType = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE assocTypeId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesWithAssocType.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); getLogEntriesWithAssocType.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesWithAssocType.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesWithAssocType.compile(); getLogEntriesForTenantWithAssocType = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE tenantId = ? AND assocTypeId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesForTenantWithAssocType.compile(); getNumberOfLogEntries = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log"); getNumberOfLogEntries.compile(); getNumberOfLogEntriesForTenant = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log WHERE tenantId = ?"); getNumberOfLogEntriesForTenant.setResultType(Integer.class); getNumberOfLogEntriesForTenant.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getNumberOfLogEntriesForTenant.compile(); deleteLogEntries = new SqlUpdate(dataSource, "TRUNCATE plugin_log"); deleteLogEntries.compile(); getComputationDurationForDate = new SqlFunction<Integer>(dataSource, "SELECT sum(timestampdiff(second, startDate, endDate)) AS sum_seconds FROM plugin_log WHERE endDate BETWEEN ? AND ?"); getComputationDurationForDate.setResultType(Integer.class); getComputationDurationForDate.declareParameter(new SqlParameter("start", Types.DATE)); getComputationDurationForDate.declareParameter(new SqlParameter("end", Types.DATE)); getComputationDurationForDate.compile(); deleteLogEntryStatement = new SqlUpdate(dataSource, "DELETE FROM plugin_log WHERE tenantId = ? AND pluginId = ? AND pluginVersion = ? AND startDate = ? AND assocTypeId = ?"); deleteLogEntryStatement.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginId", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginVersion", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("startDate", Types.TIMESTAMP)); deleteLogEntryStatement.declareParameter(new SqlParameter("assocTypeId", Types.VARCHAR)); deleteLogEntryStatement.compile(); }
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;/* ww w . ja v a 2 s. c o 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.xsystem.sql2.dml.DmlCommand.java
Object setValue(Object value, int jdbcType, String objectType, Connection con, AbstactNativeHelper nativeHelper) throws SQLException { if (jdbcType == Types.ARRAY && value != null) { List array = (List) value; value = nativeHelper.createNamedArray(con, objectType, array); } else if (jdbcType == Types.STRUCT && value != null) { Map structValue = (Map) value; value = nativeHelper.createStructure(con, objectType, structValue); } else if (jdbcType == Types.BLOB && value instanceof byte[]) { byte[] data = (byte[]) value; value = setBlob(con, data);/*from w ww . ja va 2 s. c o m*/ } else if (jdbcType == Types.CLOB && value instanceof String) { String data = (String) value; value = setClob(con, data); } return value; }
From source file:org.georepublic.db.utils.ResultSetConverter.java
public static JSONArray convertGeoJson(ResultSet rs) throws SQLException, JSONException { JSONArray json = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); JSONObject feat = new JSONObject(); feat.put("type", "Feature"); for (int i = 1; i < numColumns + 1; i++) { String column_name = rsmd.getColumnName(i); if (StringUtils.equals(column_name, "the_geom")) { continue; }//from www .j a v a 2s .c o m if (StringUtils.equals(column_name, "geojson")) { continue; } if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { obj.put(column_name, rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { obj.put(column_name, rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { obj.put(column_name, rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { obj.put(column_name, rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { obj.put(column_name, rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { obj.put(column_name, rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { obj.put(column_name, rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { obj.put(column_name, rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { obj.put(column_name, rs.getTimestamp(column_name)); } else { obj.put(column_name, rs.getObject(column_name)); } } feat.put("properties", obj); try { rs.findColumn("lon"); rs.findColumn("lat"); JSONObject geo = new JSONObject(); JSONArray coord = new JSONArray(); coord.put(rs.getDouble("lon")); coord.put(rs.getDouble("lat")); geo.put("type", "point"); geo.put("coordinates", coord); feat.put("geometry", geo); } catch (Exception ex1) { ; } json.put(feat); } return json; }
From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java
/** * {@inheritDoc}//w ww.java 2 s .c o m */ protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx, int jdbcType) throws DatabaseOperationException, SQLException { boolean useIdx = (columnName == null); if ((jdbcType == Types.LONGVARBINARY) || (jdbcType == Types.BLOB)) { InputStream stream = useIdx ? resultSet.getBinaryStream(columnIdx) : resultSet.getBinaryStream(columnName); if (stream == null) { return null; } else { byte[] buf = new byte[65536]; byte[] result = new byte[0]; int len; try { do { len = stream.read(buf); if (len > 0) { byte[] newResult = new byte[result.length + len]; System.arraycopy(result, 0, newResult, 0, result.length); System.arraycopy(buf, 0, newResult, result.length, len); result = newResult; } } while (len > 0); stream.close(); return result; } catch (IOException ex) { throw new DatabaseOperationException("Error while extracting the value of column " + columnName + " of type " + TypeMap.getJdbcTypeName(jdbcType) + " from a result set", ex); } } } else { return super.extractColumnValue(resultSet, columnName, columnIdx, jdbcType); } }