Creating a random blob in jdbc and writing it to oracle

I want to create a lot of blob in java [in memory] and write it to an Oracle table.

I want the blob [bit inside it] to be random or random, so that the oracle cannot perform a lot of preliminary optimization while saving the blob in the table.

Sort of

for(1..1000000)
{
blob = createRandomBlob(sizeOfBlob);
sqlText ="INSERT INTO test_blob (id, blob) VALUES(i, blob)";
stmt.executeUpdate(sqlText);
}

Can someone please indicate which JAVA-API I can use to create such a blob [in memory, not on disk] and write it in db?

thank

0
source share
2 answers

I think this should do the trick

  byte[] data = new byte[10000];
    fRandom.nextBytes(data);
    try
    {
      SerialBlob fSerialBlob = new SerialBlob(data);
    } catch (SerialException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

I don't know if there is a faster / more efficient way to do this.

0
source

" ", " "

byte[] someBlob = createBlobBytes();
PreparedStatement stmt = connection.prepareStatement("INSERT INTO test_blob (id, blob) VALUES(?, ?)";
ByteArrayInputStream in = new ByteArrayInputStream(someBlob);
stmt.setInt(1, id);
stmt.setBinaryStream(2, in, someBlob.length);
stmt.executeUpdate();

10.x

0

Source: https://habr.com/ru/post/1584185/


All Articles