带有“res”连接字符串的hsqldb中的Blob

时间:2012-10-12 13:06:54

标签: blob hsqldb

我有一个打包的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列读取字节失败的想法,并在使用“file”url时成功?

1 个答案:

答案 0 :(得分:1)

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

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

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