在阅读了一遍又一遍 Oracle 的文档后,不知道为什么我会遇到这个异常
原因:java.lang.ClassCastException:oracle.sql.BFILE无法转换为oracle.sql.BFILE
@Inject
@OracleProduction
private EntityManager em;
public String readBfileImage() {
Session hibernateSession = em.unwrap(Session.class);
SessionImplementor sessionImplementor = hibernateSession.unwrap(SessionImplementor.class);
Connection connection = sessionImplementor.connection();
Statement stmt = null;
BFILE my_bfile = null;
String result = "";
try {
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT BFILE_COLUMN FROM TABLE_NAME where PARAM = 1");
while (rs.next()) {
BFILE objImagen = (BFILE) rs.getObject(1); // HERE THE EXCEPTION, WHY?
System.out.println(objImagen.getName());
}
String ruta = my_bfile.getName();
result = Base64.getEncoder().encodeToString(my_bfile.getBytes());
} catch (SQLException e) {
//throwing the exception
}
return result;
}
另外,我需要找到一种方法来将图像保留在此 file_column 中,但是很难无法使用这种方式读取,很想阅读答案!
除此之外,我想分享下图来说明语句或结果集的类型是WrapperResultSetJDK8,那么这是什么意思?
您可以尝试用 java.sql.Blob 替换 oracle.jdbc.OracleBlob 吗?