具有"res"连接字符串的 hsqldb 中的 Blob



我打包了一个hsqldb数据库,一个包含我的数据库文件(mydb.script和mydb.lobs)的jar文件。

当使用"res"url (jdbc:hsqldb:res:mydb) 连接到我的数据库时,除了从 BLOB 列中获取字节外,所有查询都正常工作。这是我得到的例外:

Caused by: org.hsqldb.HsqlException: file input/output error
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.types.BlobDataID.getBytes(Unknown Source)
    at org.hsqldb.types.BlobInputStream.readIntoBuffer(Unknown Source)

当使用"file"url连接到同一个数据库时,一切正常。用于从 BLOB 列获取字节的代码如下:

// rs is ResultSet
Blob blob = rs.getBlob(i + 1);
int blobSize = (int) blob.length();
byte[] bytes = new byte[blobSize];
InputStream is = blob.getBinaryStream();
try {
    is.read(bytes, 0, blobSize);
} catch (IOException e) {
    logger.error("Error reading bytes from blob: ", e);
}

任何想法可能导致在使用"res"url 时从 BLOB 列读取字节失败,在使用"文件"url 时成功吗?

当数据库用作资源(在类路径或 jar 中)时,HSQLDB 直到版本 2.2.9 不支持 LOB。下一个版本应该支持它。

初始支持刚刚添加到最新的 HSQLDB 快照 jar 中,可以从以下位置下载:

http://www.hsqldb.org/repos/org/hsqldb/hsqldb/SNAPSHOT/

最新更新