code: @Override
     public void setBinaryStream(int parameterIndex, InputStream inputStream, int length) throws SQLException {
      if (length <= 0) {
        throw new SQLException ("Invalid length " + length);
      }
      if (inputStream == null ) {
        throw new SQLException ("Input Stream cannot be null");
      }
      final int bufferSize = 8192;
      byte[] buffer = new byte[bufferSize];
      ByteArrayOutputStream outputStream = null;
      try {
        outputStream = new ByteArrayOutputStream();
        int bytesRemaining = length;
        int bytesRead;
        int maxReadSize;
        while (bytesRemaining > 0) {
          maxReadSize = (bytesRemaining > bufferSize) ? bufferSize : bytesRemaining;
          bytesRead = inputStream.read(buffer, 0, maxReadSize);
          if (bytesRead == -1) { // inputStream exhausted
            break;
          }
          outputStream.write(buffer, 0, bytesRead);
          bytesRemaining = bytesRemaining - bytesRead;
        }
        setBytes(parameterIndex, outputStream.toByteArray());
        outputStream.close();
      } catch (IOException e) {
        throw new SQLException(e.getMessage());
      }
    }
docs: Set the parameter from the contents of a binary stream.
  @param parameterIndex the index of the parameter to set
  @param inputStream the input stream from which a byte array will be read and set as the value.  If inputStream is null
  this method will throw a SQLException
  @param length a positive non-zero length values
  @exception SQLException thrown if the length is &lt;= 0, the inputStream is null,
  there is an IOException reading the inputStream or if "setBytes" throws a SQLException