Overcomplicated oracle jdbc BLOB handling

前端 未结 9 1023
予麋鹿
予麋鹿 2020-12-04 18:20

When I search the web for inserting BLOBs into Oracle database with jdbc thin driver, most of the webpages suggest a 3-step approach:

  1. insert empty_blob()
9条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 18:41

    I found a simple call to setObject(pos, byte[]) works for my case. From Database Programming with JDBC and Java By George Reese,

            byte[] data = null;
            stmt = con.prepareStatement("INSERT INTO BlobTest(fileName, "
                + "blobData) VALUES(?, ?)");
            stmt.setString(1, "some-file.txt");
            stmt.setObject(2, data, Types.BLOB);
            stmt.executeUpdate();
    

提交回复
热议问题