2014-01-15 50 views
1

我工作的一個項目再保理舊的J2EE項目spring3/MyBatis的嘗試使用spring3獲得從Oracle DB斑點和MyBatis的

我目前有獲取保存在一個blob一個PDF問題oracle表。

原始代碼返回135896bytes的byte [],spring/mybatis返回86bytes的byte []。所以我做錯了什麼。感謝您的幫助

原始代碼看起來像::

 byte[] filebytes = null; 
     con = SvcsConnection.getDBConnection("drugdb"); 
     String qry = "SELECT pm_blob FROM pdf_master WHERE pm_id_seq = '" +id + "'"; 
     oracle.sql.BLOB blob; 
     stmt = con.createStatement(); 
     rs = stmt.executeQuery(qry);  
     //set mime type 
     if(rs.next()) { 
      blob = ((OracleResultSet) rs).getBLOB("pm_blob"); 
      filebytes = blob.getBytes(1, (int) blob.length());         
     } 

filebytes在以後的getBytes是135896bytes

在我的春天的東西

我有以下

映射

<select id="getPdfMaster" parameterType="int" resultType="org.uhs.formulary.pdf_master.model.Pdf_Master"> 
    SELECT pm_id_seq, pm_filename, pm_title, pm_blob, pm_update_datetime, pm_update_source, 
    to_char(pm_update_datetime, 'MM/DD/YYYY') as pm_update_datetime_str 
    FROM pdf_master WHERE pm_id_seq = #{pm_id_seq} 
</select> 

DAO

@Repository 
public interface PdfMasterDao { 
    public List<Pdf_Master> getPdfMaster(int pm_id_seq); 
} 

模型(片斷)

public byte[] getPm_Blob() { 
    return pmBlob; 
} 

getPm_Blob同樣的事情

回答

0

指定jdbc類型爲BLOB返回[] 86的字節

<resultMap id="kpDataMap" type="KPData"> 
     <id property="kpId" jdbcType="INTEGER" column="KPID" /> 
     <result property="fName" jdbcType="VARCHAR" column="FNAME" /> 
     <result property="lName" jdbcType="VARCHAR" column="LNAME" /> 
     <result property="salary" jdbcType="BIGINT" column="SALARY"/> 
     <result property="img" jdbcType="BLOB" column="IMG" /> 
    </resultMap> 

    <insert id="setKPData" parameterType="KPData"> 
     INSERT INTO KPDATA(KPID,FNAME,LNAME,SALARY,IMG) 
     VALUES(#{kpId},#{fName},#{lName},#{salary, javaType=java.math.BigInteger, jdbcType=BIGINT},#{img, jdbcType=BLOB}) 
    </insert> 

    <select id="getKPData" resultMap="kpDataMap"> 
     SELECT KPID,FNAME,LNAME,SALARY,IMG 
     FROM KPDATA 
     WHERE KPID=#{kpId} 
    </select> 


public class KPData { 

    private int kpId; 
    private String fName; 
    private String lName; 
    private BigInteger salary; 
    private byte[] img; 

     //getters and setters 


}