- void insert(final Connection conn, final int key, final byte[] data) throws IOException, SQLException {
- final BlobInsertInvoker invoker = new BlobInsertInvoker(conn);
- try {
- invoker.setInputParameter(key, new ByteArrayInputStream(data), data.length);
- invoker.executeUpdate();
- } finally {
- invoker.close();
- }
- }
- byte[] select(final Connection conn, final int key) throws IOException, SQLException {
- final BlobSelectIterator iterator = new BlobSelectIterator(conn);
- try {
- iterator.setInputParameter(key);
- final BlobSelectRow row = iterator.getSingleRow();
- final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- final InputStream inStream = row.getDat();
- final byte[] buf = new byte[8192];
- for (;;) {
- final int length = inStream.read(buf);
- if (length < 0) {
- break;
- }
- outStream.write(buf, 0, length);
- }
- outStream.flush();
- outStream.close();
- inStream.close();
- return outStream.toByteArray();
- } finally {
- iterator.close();
- }
- }