我正在尝试为Postgres的BLOB创建一个MyBatis自定义FILE类型处理程序。JDBC:如何获得当前连接?
这是我需要实现履行接口中的方法:
@Override
public File getNullableResult(ResultSet rs, String columnName) throws SQLException {
1.get current connection
2.get postgreSQL LargeObjectManager from current connection
3.get oid from ResultSet, so the Larget Object can be found
4.read the large object and rewrite it into a file
5.return the file
}
但是我不知道如何在这种情况下,当前的连接。有没有办法从ResultSet获取连接?
由于提前,
UPDATE:
PostgreSQL实现了一滴在一个特殊(非标准也许)方式(大对象,而不是BYTEA)。它将所有blob保存在pg_largeobject表中,并将oid用作“指针”,以便您可以从实际表中引用blob。
Postgres JDBC驱动程序已经分离API来处理blob。在下面的链接的更多细节: http://jdbc.postgresql.org/documentation/91/binary-data.html
你就不能获得BLOB直接从结果集? –
@MarkRotteveel不,PostgreSQL以特殊的方式实现blob。它将所有blob保存在pg_largeobject表中,并将oid用作“指针”,以便您可以从实际表中引用blob。 – Xin
有趣的是,我希望postgresql JDBC驱动程序隐藏该实现细节。 –