Help required regarding showing pdf from blob data.
2008-09-01 05:50:04 GMT
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. |
Clinton
On Tue, Sep 2, 2008 at 11:45 AM, Jeff Butler <jeffgbutler <at> gmail.com> wrote:
> If you use a <parameterMap>, then you must use question marks as markers in
> your statement. I suggest you skip the parameter map completely and specify
> the type handler in the statement:
>
> #keyList[],handler=com.jrapp.ibatis.KeyHandlerCallback#
>
> BTW - declared parameter maps will likely go away with iBATIS 3 - we don't
> like them AT ALL for this exact reason - they are too confusing to use.
>
> Jeff Butler
>
> On Tue, Sep 2, 2008 at 12:32 PM, J R <power_of_s <at> yahoo.com> wrote:
>>
>> Clinton this does not seem to work. Any other ideas? Any other way around
>> to
>> handle this?
>>
>> Thanks!
>>
>>
>> Clinton Begin wrote:
>> >
>> > Upgrade to 2.3.3
>> >
>> > Cheers,
>> > Clinton
>> >
>> > On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
>> >
>> >>
>> >> I have a parameterClass which holds List and a Long, and I have to
>> >> invoke
>> >> a
>> >> typeHandler on List to fit some custom logic. But seems like the
>> >> typeHandler
>> >> is not getting invoked.
>> >>
>> >> Intent is to have typeHandler invoked so that I can customize the items
>> >> in
>> >> the List. Is typeHandler invoked for each reference to list element? or
>> >> am
>> >> I
>> >> doing something wrong?
>> >>
>> >> <parameterMap id="queryCustomization"
>> >> class="com.jrapp.customizations.QueryObject">
>> >> <parameter property="keyCount" />
>> >> <parameter property="keyList"
>> >> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>> >> </parameterMap>
>> >>
>> >> public class QueryObject{
>> >>
>> >> private Long keyCount = 0;
>> >> private ArrayList KeyList = new ArrayList();
>> >>
>> >> // With proper getters and setters
>> >> }
>> >>
>> >> Snippet of ibatis sqlmap:
>> >>
>> >> <dynamic>
>> >> <isGreaterThan property="keyCount" compareValue="0">
>> >> and (
>> >> q.objectListKey in (
>> >> <iterate property="keyList" conjunction=",">
>> >> #keyList[]#
>> >> </iterate>
>> >> )
>> >> </dynamic>
>> >>
>> >> ..So I expect that on "keyList[]" reference in above sqlmap,
>> >> typehandler
>> >> would be invoked. Is that wrong assumption? Any way to achieve this?
>> >>
>> >> Thanks!
>> >> --
>> >> View this message in context:
>> >>
>> >>
RSS Feed