Postgres和大对象:无效的大对象描述符:0 [英] Postgres and Large Objects: invalid Large-Object-Descriptor: 0

查看:71
本文介绍了Postgres和大对象:无效的大对象描述符:0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java应用程序中,我使用LargeObject接口写入类型为lo(大对象)的二进制数据:

In my Java App im writing binary data of type lo (large object) using the LargeObject Interface:

        LargeObjectManager lLOManager = ((org.postgresql.PGConnection) aDatabaseConnection).getLargeObjectAPI();
        long oid = lLOManager.createLO();
        LargeObject lo = lLOManager.open(oid, LargeObjectManager.WRITE);

        if (aBLOB != null)
            lo.write(aBLOB);

        lo.close();

在读取表格时,我使用相同的api获取输入流:

When reading the table i use the same api to get an inputstream:

LargeObjectManager lLOManager = ((org.postgresql.PGConnection) aDatabaseConnection).getLargeObjectAPI();
            long lOid = aRs.getLong(aIndex);
            if (lOid != 0)
            {
                LargeObject lObj = lLOManager.open(lOid, LargeObjectManager.READ);
                inputStream = lObj.getInputStream();
                lObj.close();
            }

但是,当我尝试读取流时,出现异常:

However, when i then try to read the stream i get an exception:

int number = inputStream.read()

或者

byte[] byteArray = new byte[1024];
int number = inputStream.read(byteArray);

例外:

org.postgresql.util.PSQLException:错误:无效的大对象描述符:0

org.postgresql.util.PSQLException: ERROR: invalid large-object descriptor: 0

我在这里总结了代码,因为在我的应用程序中它是分布式的.关键是当前来自输入流的内容已被读取,而该流所来自的数据库连接已关闭.但是,该代码以前在postgres上可以使用,但在oracle上仍然可以使用.我尝试将Postgres驱动程序9.3和42.1.4与Postgres 9.2一起使用.

i summed up the code here, because in my app it is distributed. The point is that currently the content from the inputstream is read, when the db connection the stream is coming from is already closed. However, the code used to work some time ago for postgres and still does for oracle. I'm tried using postgres driver 9.3 as well as 42.1.4 together with Postgres 9.2.

我的问题:从SQL结果集派生的Java输入流是否独立于数据库连接和结果集的状态?

My Question: Is a java inputstream derived from a sql resultset independent from the status of the db connection and resultset?

推荐答案

关闭大对象后,您将无法读取它.

You cannot read from the large object after you have closed it.

此外,打开和读取大对象必须在一个数据库事务中发生.大对象在事务结束时关闭.

Also, opening and reading a large object must happen in one database transaction. The large object is closed at the end of the transaction.

这篇关于Postgres和大对象:无效的大对象描述符:0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆