Hi,
We are using Ibatis with Spring in our project. We have requirement to store pdf files in the database as blob columns and retrieve them and show them again as pdf. Currently we are doing the following. 1. We are converting the pdf file into a byte array and saving it as a blob column 2. While retrieving we are reading the blob column as a byte array 3. While converting the byte array to pdf, we are facing encoding problems. A pdf file is generated and data is written into it, but when we try to open it says 'Cannot open because it is not a supported file type or the file has been damaged'. Please refer the files attached. In the main method, we try to insert a row into the employee table. The 'description' field is a blob column in the Employee table. // This is the code for retrieval Employee emp1 = (Employee) sqlMap.queryForObject("getEmployee", "45"); byte[] desc=emp1.getDesc(); String filename="abc.pdf"; FileOutputStream fos=new FileOutputStream(filename); fos.write(desc); fos.close(); Please tell us, how can we convert the byte array to pdf file. Please tell us if there are any other ways to achieve this functionality. We feel that it has something to do with the encoding formats. Regards, Ananth. This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful.
Employee.java
Description: Employee.java
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sqlMap namespace="Employee"> <resultMap id="insertEmployees" class="com.orc.ibatis.Employee"> <result property="empno" column="EMPID" /> <result property="name" column="ENAME" /> <result property="salary" column="SALARY" /> <result property="desc" column="DESCRIPTION" jdbcType="BLOB" javaType="[B"/> </resultMap> <select id="getEmployee" resultMap="insertEmployees"> SELECT EMPID , ENAME , SALARY , DESCRIPTION FROM EMP2 WHERE EMPID = #empno# </select> <insert id="insertingBlob" parameterClass="com.orc.ibatis.Employee"> INSERT INTO EMP2(EMPID,"ENAME",SALARY,"DESCRIPTION") values(#empno#,#name#,#salary#,#desc#) </insert> </sqlMap>
TestIbatis.java
Description: TestIbatis.java