JPA-使用BLOB参数调用存储过程
我正在使用JPA2.0。我想调用一个Oracle存储过程。其中一个参数是BLOBJPA-使用BLOB参数调用存储过程,jpa,stored-procedures,blob,Jpa,Stored Procedures,Blob,我正在使用JPA2.0。我想调用一个Oracle存储过程。其中一个参数是BLOB PROCEDURE test(file IN BLOB); 我试图用下一个代码调用它: byte[] bytes = ...; Query query = em.createNativeQuery("{ CALL test(?) }"); query.setParameter(1, bytes); query.executeUpdate(); 我得到了下一个错误: PLS-00306:调用“测试”时参数的数量或
PROCEDURE test(file IN BLOB);
我试图用下一个代码调用它:
byte[] bytes = ...;
Query query = em.createNativeQuery("{ CALL test(?) }");
query.setParameter(1, bytes);
query.executeUpdate();
我得到了下一个错误:
PLS-00306:调用“测试”时参数的数量或类型错误
问题是如何传递blob参数,因为我可以在没有blob参数的情况下调用其他存储过程
谢谢试试这个:
@Override
public void insertData(DataSource ds, byte[] data) throws SQLException {
Connection conn = null;
CallableStatement cstmt = null;
try {
conn = ds.getConnection();
cstmt = conn.prepareCall("{call test (?)}");
Blob blob = conn.createBlob();
blob.setBytes(1, data);
cstmt.setBlob(1, blob);
cstmt.execute();
} finally {
if (cstmt != null) {
cstmt.close();
}
if (conn != null) {
conn.close();
}
}
}
感谢您的JDBC解决方案,但我希望使用JPA框架来实现。我也遇到了同样的问题。但我使用注释@NamedStoredProcedureQuery。我还想用JPA框架解决这个问题。