Postgres:如何使用JDBC API插入oid值,postgresoid,conn.setAuto
分享于 点击 6393 次 点评:158
Postgres:如何使用JDBC API插入oid值,postgresoid,conn.setAuto
conn.setAutoCommit(false);// Get the Large Object Manager to perform operations withLargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI();// Create a new large objectint oid = lobj.create(LargeObjectManager.READ | LargeObjectManager.WRITE);// Open the large object for writingLargeObject obj = lobj.open(oid, LargeObjectManager.WRITE);// Now open the fileFile file = new File("myimage.gif");FileInputStream fis = new FileInputStream(file);// Copy the data from the file to the large objectbyte buf[] = new byte[2048];int s, tl = 0;while ((s = fis.read(buf, 0, 2048)) > 0) { obj.write(buf, 0, s); tl += s;}// Close the large objectobj.close();//laterps.setInt(<index>, oid);conn.commit();conn.close();
用户点评