List of usage examples for java.sql PreparedStatement setBytes
void setBytes(int parameterIndex, byte x[]) throws SQLException;
From source file:org.sonar.server.source.db.FileSourceTesting.java
public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException { PreparedStatement stmt = connection .prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='" + FileSourceDto.Type.SOURCE + "'"); stmt.setBytes(1, data); stmt.setString(2, fileUuid);//from w ww . j a va 2 s. c o m stmt.executeUpdate(); stmt.close(); }
From source file:libepg.util.db.AboutDB.java
/** * ?DB?????//from w w w . j av a 2 s.c o m * @param src * @param conn DB?? * @throws java.sql.SQLException * @see libepg.util.db.AboutDB#CRATE_TABLE * @see java.sql.Connection#createStatement() */ public static synchronized void convertToTable(List<TsPacket> src, Connection conn) throws SQLException { Statement stmt = conn.createStatement(); //? stmt.executeUpdate(AboutDB.CRATE_TABLE); //?PID?????? for (TsPacket tsp : src) { PreparedStatement insertStatement = conn.prepareStatement(INSERT_SQL); insertStatement.setInt(1, tsp.getPid()); insertStatement.setInt(2, tsp.getContinuity_counter()); insertStatement.setInt(3, 0); insertStatement.setBytes(4, tsp.getData()); insertStatement.executeUpdate(); } }
From source file:edu.jhu.pha.vospace.jobs.JobsProcessor.java
public static void modifyJobState(final JobDescription job, final STATE state, final String note) { if (null == job.getEndTime() && (state == STATE.COMPLETED || state == STATE.ERROR)) { job.setEndTime(new Date()); }//w w w . j a v a2 s . c om job.setState(state); final byte[] jobBytes; try { jobBytes = (new ObjectMapper()).writeValueAsBytes(job); } catch (Exception ex) { throw new InternalServerErrorException(ex.getMessage()); } DbPoolServlet.goSql("Modify job", "update jobs set endtime = ?, state = ?, json_notation = ?, note = ? where id = ?", new SqlWorker<Integer>() { @Override public Integer go(Connection conn, PreparedStatement stmt) throws SQLException { stmt.setString(1, (null == job.getEndTime()) ? null : dateFormat.format(job.getEndTime().getTime())); stmt.setString(2, job.getState().toString()); stmt.setBytes(3, jobBytes); stmt.setString(4, (null == note) ? "" : note); stmt.setString(5, job.getId()); return stmt.executeUpdate(); } }); logger.debug("Job " + job.getId() + " is modified. " + job.getState()); }
From source file:org.osmdroid.geopackagetoosm.Main.java
/** * Write formatted tiles//from ww w. j a v a 2 s. co m * * @param tileDao * @param zoomLevel * @param tileMatrix * @param zDirectory * @param imageFormat * @param tileType * @param rawImage * @return * @throws IOException */ private static int writeFormatTiles(TileDao tileDao, long zoomLevel, TileMatrix tileMatrix, File zDirectory, String imageFormat, TileFormatType tileType, boolean rawImage, String layer) throws IOException, SQLException { int tileCount = 0; // Get the projection of the tile matrix set long epsg = tileDao.getTileMatrixSet().getSrs().getOrganizationCoordsysId(); Projection projection = ProjectionFactory.getProjection(epsg); // Get the transformation to web mercator Projection webMercator = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR); ProjectionTransform projectionToWebMercator = projection.getTransformation(webMercator); // Get the tile matrix set and bounding box TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet(); BoundingBox setProjectionBoundingBox = tileMatrixSet.getBoundingBox(); BoundingBox setWebMercatorBoundingBox = projectionToWebMercator.transform(setProjectionBoundingBox); // Determine the tile grid in the world the tiles cover TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(setWebMercatorBoundingBox, (int) zoomLevel); // Go through each tile in the tile grid for (long x = tileGrid.getMinX(); x <= tileGrid.getMaxX(); x++) { // Build the z/x directory //File xDirectory = new File(zDirectory, String.valueOf(x)); for (long y = tileGrid.getMinY(); y <= tileGrid.getMaxY(); y++) { // Get the y file name for the specified format long yFileName = y; if (tileType == TileFormatType.TMS) { yFileName = TileBoundingBoxUtils.getYAsOppositeTileFormat((int) zoomLevel, (int) y); } //File imageFile = new File(xDirectory, String.valueOf(yFileName) // + "." + imageFormat); TileRow tileRow = null; BufferedImage image = null; if (rawImage) { tileRow = TileDraw.getRawTileRow(tileDao, tileMatrix, setWebMercatorBoundingBox, x, y, zoomLevel); } else { // Create the buffered image image = TileDraw.drawTile(tileDao, tileMatrix, imageFormat, setWebMercatorBoundingBox, x, y, zoomLevel); } if (tileRow != null || image != null) { // Make any needed directories for the image // xDirectory.mkdirs(); //((z << z) + x << z) + y long key = ((zoomLevel << zoomLevel) + x << zoomLevel) + y; if (rawImage) { // Write the raw image bytes to the file PreparedStatement prepareStatement = con .prepareStatement("insert into tiles (key,provider, tile) values (?,?,?);"); prepareStatement.setLong(1, key); prepareStatement.setString(2, layer); prepareStatement.setBytes(3, tileRow.getTileData()); prepareStatement.execute(); prepareStatement.close(); //FileOutputStream fos = new FileOutputStream(imageFile); //fos.write(tileRow.getTileData()); //fos.close(); } else { // Write the image to the file ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, imageFormat, baos); //ImageIO.write(image, imageFormat, imageFile); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); //X/Y/Z PreparedStatement prepareStatement = con .prepareStatement("insert into tiles (key,provider, tile) values (?,?,?);"); prepareStatement.setLong(1, key); prepareStatement.setString(2, layer); prepareStatement.setBytes(3, imageInByte); prepareStatement.execute(); prepareStatement.close(); } tileCount++; if (tileCount % ZOOM_PROGRESS_FREQUENCY == 0) { LOGGER.log(Level.INFO, "Zoom " + zoomLevel + " Tile Progress... " + tileCount); } } } } return tileCount; }
From source file:org.intermine.modelproduction.MetadataManager.java
/** * Store a binary (key, value) pair in the metadata table of the database * @param database the database//www . jav a2 s .c o m * @param key the key * @param value the byte array of the value * @throws SQLException if an error occurs */ public static void storeBinary(Database database, String key, byte[] value) throws SQLException { Connection connection = database.getConnection(); boolean autoCommit = connection.getAutoCommit(); try { connection.setAutoCommit(false); ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM " + METADATA_TABLE); ResultSetMetaData meta = rs.getMetaData(); if (meta.getColumnCount() != 3) { connection.createStatement().execute("ALTER TABLE " + METADATA_TABLE + " ADD blob_value BYTEA"); } connection.createStatement().execute("DELETE FROM " + METADATA_TABLE + " where key = '" + key + "'"); PreparedStatement pstmt = connection.prepareStatement( "INSERT INTO " + METADATA_TABLE + " (key, blob_value) " + "VALUES('" + key + "', ?)"); pstmt.setBytes(1, value); pstmt.executeUpdate(); connection.commit(); pstmt.close(); } finally { connection.setAutoCommit(autoCommit); connection.close(); } }
From source file:at.becast.youploader.database.SQLite.java
public static void updatePlaylist(Item item) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `playlists` SET `name`=?,`image`=? WHERE `playlistid`=?"; prest = c.prepareStatement(sql);//from w w w . j ava 2s. c o m prest.setString(1, item.snippet.title); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(2, imageBytes); prest.setString(3, item.id); prest.execute(); prest.close(); }
From source file:at.becast.youploader.database.SQLite.java
public static void insertPlaylist(Item item, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`,`shown`) " + "VALUES (?,?,?,?,1)"; prest = c.prepareStatement(sql);//from ww w .j a v a 2 s .co m prest.setString(1, item.snippet.title); prest.setString(2, item.id); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); }
From source file:at.becast.youploader.database.SQLite.java
public static void savePlaylists(Playlists playlists, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`) " + "VALUES (?,?,?,?)"; for (Playlists.Item i : playlists.items) { prest = c.prepareStatement(sql); prest.setString(1, i.snippet.title); prest.setString(2, i.id);//from w ww. ja v a 2 s . c o m URL url = new URL(i.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); } }
From source file:dao.CarryonTagCaptionUpdateQuery.java
/** * This method is not called by spring./*from ww w . j av a2s. c om*/ * * @param conn the connection is passed to this method * @param btitle the title of the blob * @param entryid entryid * @param loginid loginid */ public void run(Connection conn, String title, String entryid, String loginid) throws BaseDaoException { byte[] caption = { ' ' }; if (!RegexStrUtil.isNull(title)) { caption = title.getBytes(); } String query = "update carryontag set title=? where entryid=" + entryid + " and ownerid=" + loginid + ""; try { PreparedStatement stmt = conn.prepareStatement(query); stmt.setBytes(1, caption); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update only caption for carryontag " + query, e); } }
From source file:dao.ContactTagUpdateQuery.java
/** * Method updates usertag information for a given contact id * @param conn - the connection/*from w ww . j ava 2 s . co m*/ * @param contactid - the contactid * @param usertags - the usertags * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String contactid, String usertags) throws BaseDaoException { byte[] mytags = { ' ' }; if (!RegexStrUtil.isNull(usertags)) { mytags = usertags.getBytes(); } try { String stmt = "update contactstag set usertags=? where contactid=" + contactid + " limit 1"; PreparedStatement query = conn.prepareStatement(stmt); query.setBytes(1, mytags); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update contactstag", e); } }