开发者

creating a random blob in jdbc and writing it to oracle

开发者 https://www.devze.com 2023-01-28 09:39 出处:网络
I want to create many bl开发者_开发百科obs in java [in memory] and write it to Oracle table. What I want is the blob[bits inside it] to be random or sudo random so that oracle would not be able to d

I want to create many bl开发者_开发百科obs in java [in memory] and write it to Oracle table.

What I want is the blob[bits inside it] to be random or sudo random so that oracle would not be able to do a lot of pre-optimization while storing the blob to the table.

Something like

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

Can someone point what JAVA APIs I can use to create such blob[in memory rather than on disk] and write it to db ?

Thanks


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();
    }

Dont know if there is a faster/efficient way of doing it.


I can only answer for the "store it in the DB part", not sure about the "create a random blob array)

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();

This should work fine with the 10.x drivers

0

精彩评论

暂无评论...
验证码 换一张
取 消