2016-08-19 67 views
2

在mybatis,spring應用程序中,我有一個TypeHandler,它填充調用Oracle存儲過程所需的STRUCTS數組的數據。 blob條目在存儲過程中正確填充並可見;字符串條目不是,沒有字符串數據被髮送。日誌中沒有打印錯誤或警告。數據不爲空並且在應用程序中有效。數據在應用程序和oracle之間簡單消失。Ibatis TypeHandler和存儲過程類型中的空Varchar參數

我的處理程序的執行setParameter看起來像這樣:

public void setParameter(PreparedStatement ps, int i, List<MailAttachment> parameter, 
    JdbcType jdbcType) throws SQLException 
{ 
    List<MailAttachment> attachmentList = parameter; 

    OracleConnection oracleConnection = ps.getConnection().unwrap(OracleConnection.class); 

    StructDescriptor structDescriptor = StructDescriptor.createDescriptor(ATTACHMENT, oracleConnection); 
    Object[] structs = null; 
    structs = new Object[attachmentList == null ? 0 :attachmentList.size()]; 
    if (attachmentList != null) { 
     //CharacterSet chs = CharacterSet.make(CharacterSet.UTF8_CHARSET); 
     for (int index = 0; index < attachmentList.size(); index++) { 

      MailAttachment mailAttachment = attachmentList.get(index); 
      BLOB blob = null; 
      if (mailAttachment.getData() != null){ 
       blob = BLOB.createTemporary(oracleConnection,false,BLOB.DURATION_SESSION); 
       // filling blob works 
      } 
      CHAR attachName = new CHAR(mailAttachment.getFilename(), CharacterSet.make(CharacterSet.UTF8_CHARSET)); 
      CHAR contentType = new CHAR(mailAttachment.getContentType(), CharacterSet.make(CharacterSet.UTF8_CHARSET)); 

      STRUCT struct = new STRUCT(structDescriptor, oracleConnection, 
           new Object[] {blob, attachName, contentType, null} 
           ); 
      structs[index] = struct; 
     } 
    } 

    ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(ATTACHMENT_LIST, oracleConnection); 
    ARRAY oracleArray = new ARRAY(arrayDesc, oracleConnection, structs); 
    ps.setObject(i, oracleArray); 
} 

回答

1

此問題與Oracle JDBC驅動程序連接,它的國際化支持。

請記住將orai18n.jar包含在classpath/pom文件中,其版本爲您的ojdbc jar文件的正確版本。

如果orai18n.jar丟失:

  • setParameters:VARCHAR2參數中的Oracle的類型將被設置爲空
  • 的getResult/getNonNullParameter:VARCHAR2參數將被裝載到Java類爲 「???」串。