I am working on a project re factoring an old j2ee project to spring3/mybatis
I am currently having problem retrieving a PDF saved as a blob in an oracle table.
The original code returns a byte[] of 135896bytes and the spring/mybatis returns byte[] of 86bytes. So am i doing something incorrectly. Thanks for any help
The original code looked like::
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 after the getBytes is 135896bytes
in my spring stuff i have the following
mapper
<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);
}
Model (snippet)
public byte[] getPm_Blob() {
return pmBlob;
}
getPm_Blob returns a byte[] of 86 for the same thing
Specify the jdbcType as 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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.