简体   繁体   English

尝试使用spring3和mybatis从Oracle数据库中获取Blob

[英]trying to get a blob from an oracle DB using spring3 and mybatis

I am working on a project re factoring an old j2ee project to spring3/mybatis 我正在做一个将旧的j2ee项目分解为spring3 / mybatis的项目

I am currently having problem retrieving a PDF saved as a blob in an oracle table. 我目前在检索保存为Oracle表中的Blob的PDF时遇到问题。

The original code returns a byte[] of 135896bytes and the spring/mybatis returns byte[] of 86bytes. 原始代码返回135896bytes的byte [],而spring / mybatis返回86bytes的byte []。 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 getBytes为135896bytes后的filebytes

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 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 对于同一件事,getPm_Blob返回86的byte []

Specify the jdbcType as blob 将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


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM