Greetings!
I've got a problem trying to read a BLOB from a PostgreSql table.
I can upload and save a file (jpeg in this case) but can't get it back.
I'm saving it as a part of bean and I'm trying to retrieve all the data back into a bean.
I looked at the example of using BLOB on the iBatis site and I found a lot references on reading a BLOB through raw JDBC, but I can't find an example of iBatis & PostgreSql doing it.
Here's the error I'm getting:
Jul 12, 2007 10:26:38 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
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...
--- 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 : \37...
Caused by: org.postgresql.util.PSQLException: Bad value for type int : \37
Caused by: com.ibatis.common.jdbc.exception.NestedSQLExceptio n:
--- 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 : \3
at com.ibatis.sqlmap.engine.mapping.statement.General Statement.executeQueryWithCallback(GeneralStatemen t.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.General Statement.executeQueryForObject(GeneralStatement.j ava:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.queryForObject(SqlMapExecutorDelegate.java:565)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.queryForObject(SqlMapExecutorDelegate.java:540)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.qu eryForObject(SqlMapSessionImpl.java:106)
at org.springframework.orm.ibatis.SqlMapClientTemplat e$1.doInSqlMapClient(SqlMapClientTemplate.java:243 )
at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMapClientTemplate.java:193)
at org.springframework.orm.ibatis.SqlMapClientTemplat e.queryForObject(SqlMapClientTemplate.java:241)
at com.persistance.dao.ImagesSqlMapDao.getImage(Image sSqlMapDao.java:38)
at com.controllers.UploadImagesController.showImage(U ploadImagesController.java:96)
... table
... beanCode:CREATE TABLE images ( image_name character varying(30) NOT NULL, image_description character varying(250) NOT NULL, image_size bigint NOT NULL, image_file bytea NOT NULL -- the image file itself ) WITH OIDS;
iBatis:Code:private int imageId; private String imageName; private String imageDescription; private long imageSize; private byte[] imageBody; ... setters and getters....
Code:<typeAlias alias="storyImage" type="com.domain.StoryImage"></typeAlias> <resultMap id="getImageResult" class="storyImage" > <!-- --> <result property="imageName" column="image_name" /> <result property="imageDescription" column="image_description" /> <result property="imageSize" column="image_size" /> <result property="imageBody" column="image_file" jdbcType="BLOB" /> </resultMap> <insert id="saveImage" parameterClass="storyImage" > INSERT INTO images ( image_name, image_description, image_size, image_file ) VALUES ( #imageName#, #imageDescription#, #imageSize#, #imageBody# ); </insert> <select id="getImage" resultMap="getImageResult" resultClass="storyImage" parameterClass="string" > SELECT * FROM images WHERE image_name = #imageName#; </select>
... any help will be most appreciated![]()


Reply With Quote