From: | tomasz brymora <tomekpilot(at)yahoo(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | BLOB, iBatis and PostgreSql |
Date: | 2007-07-13 18:45:25 |
Message-ID: | 531615.4242.qm@web56609.mail.re3.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Greetings!
I got lost trying to save and read an image file from
a db.
I get file upload taken care of where a servlet
populates a bean with the image file and other info,
but I can't get to be written to the db.
What's the best way to procede, starting with the
bean?
Would this be appropriate: private MultipartFile
imageBody;
Given the following table:
CREATE TABLE story_image
(
image_name varying ( 30 ),
image_description varying (50),
image_body oid
);
... waht's the correct way to make the insert?
I'm using iBatis for handling the jdbc part of the
app.
... partial iBatis sqlMap:
<insert id="saveImage" parameterClass="storyImage" >
INSERT INTO images
(
image_name,
image_description,
image_file
)
VALUES
( #imageName#,
#imageDescription#,
lo_import( #imageBody# )
);
</insert>
... from what I gathered, pg uses a path to the image
file for importing it, so should I store to a temp dir
on
the server and feed pg the path to it?
Would the bean then require a String for the imageBody
variable instead of the MultipartFile?
Am I using the datatype for this operation (oid)?
Before this I was able to store the image file in the
db as 'bytea' but ran into problems trying to
retrieve it:
INFO: Loading XML bean definitions from class path
resource
[org/springframework/jdbc/support/sql-error-codes.xml]
org.springframework.dao.DataIntegrityViolationExce
ption: SqlMapClient operation; SQL [];
--- The error occurred in
com/persistance/sqlmaps_xml/imagesSqlMap.xml.
--- The error occurred while applying a result map.
--- Check the getImageResult.
--- Check the result mapping for the 'imageBody'
property.
--- Cause: org.postgresql.util.PSQLException: Bad
value for type int : \377 ... rest omitted...
... so I'll appreciate any feedback you might have.
From | Date | Subject | |
---|---|---|---|
Next Message | Eric Faulhaber | 2007-07-15 06:10:25 | Implicit autocommit? |
Previous Message | Michael Schmidt | 2007-07-13 18:02:42 | Re: backup through Java |