2014-10-20 91 views
0

我正在使用JPA 2.0。我想调用一个Oracle存储过程。其中一个参数是BLOB。JPA - 使用BLOB参数调用存储过程

PROCEDURE test(file IN BLOB); 

我想下一个代码来调用它:

byte[] bytes = ...; 
Query query = em.createNativeQuery("{ CALL test(?) }"); 
query.setParameter(1, bytes); 
query.executeUpdate(); 

,我发现了一个错误:

PLS-00306:错号码或类型的调用参数'测试'

问题是如何传递blob参数,因为我可以调用其他存储过程而无blob参数。

感谢

回答

0

试试这个:

@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(); 
     } 
    } 
} 
+0

感谢您的JDBC的解决方案,但我想使用JPA框架来做到这一点。 – Eduardo 2014-10-21 06:49:21

相关问题