我正在开发一个项目,将旧的j2ee项目分解为spring3 / mybatis
我目前在检索在oracle表中保存为blob的PDF时遇到问题。
原始代码返回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());
}
getBytes 135896bytes 之后的filebytes
在我的春天,我有以下
映射器
<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为同一件事返回一个86的byte []
答案 0 :(得分:0)
将jdbcType指定为blob
<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
}