2016-08-19 2 views
2

mybatis에서 스프링 애플리케이션에는 Oracle의 저장 프로 시저를 호출하는 데 필요한 STRUCTS의 ARRAY 데이터를 채우는 TypeHandler가 있습니다. BLOB 항목이 저장 프로 시저에서 올바르게 채워지고 표시됩니다. 문자열 항목이 없으며 문자열 데이터가 전송되지 않습니다. 로그에 오류나 경고가 인쇄되지 않았습니다. 데이터가 null이 아니며 응용 프로그램에 유효합니다. 애플리케이션과 오라클간에 데이터가 사라집니다.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 파라미터하는 것은 null로 설정됩니다
  • getResult를/getNonNullParameter : VARCHAR2 매개 변수가 "???"로 자바 클래스에로드됩니다 끈.