欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Postgres:如何使用JDBC API插入oid值,postgresoid,conn.setAuto

来源: javaer 分享于  点击 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();
相关栏目:

用户点评