Announcement Announcement Module
Collapse
No announcement yet.
iBATIS/MySQL: error in syntax? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • iBATIS/MySQL: error in syntax?

    I'm trying to make BLOB insertion using Spring / iBATIS / MySQL work. Here's what I got so far

    the sqlmap:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
    <sqlMap>
    	<typeAlias alias="image" type="pay.dao.ibatis.test.ImageDO" />
    		<resultMap class="image" id="image">
    			<result property="id" column="id" />
    			<result property="desc" column="desc" />
    			<result property="image" column="image" jdbcType="BLOB" javaType="[B" />
    		</resultMap>
    
    
    
    	<insert id="insertRecord" parameterClass="image">
    		insert into pay_testblob (id,desc,image) values (#id#,#desc#,#image#)
    	</insert>
    	
    	<update id="updateImage" parameterClass="image">
    		update pay_testblob set image =#image# where id = #id#
    	</update>
    	<select id="getImageById" parameterClass="int" resultClass="java.lang.String">
    		select image from pay_testblob where id = #id#
    	</select>
    </sqlMap>
    The weird part is that I get this error when I invoke the insert :

    Code:
    2007-07-13 02:19:23,390 main
     [DEBUG] org.springframework.jdbc.support.SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@2bc3f5]: name is 'MySQL'
    2007-07-13 02:19:23,390 main
     [DEBUG] org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'MySQL' found
    2007-07-13 02:19:23,390 main
     [DEBUG] org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQL state '42000', error code '1064', message [  
    --- The error occurred in ibatis/image.xml.  
    --- The error occurred while applying a parameter map.  
    --- Check the insertRecord-InlineParameterMap.  
    --- Check the statement (update failed).  
    --- Cause: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc,image) values (1,'image1',_binary'\0JFIF\0\0\0\0\0\0C\0' at line 1]; SQL was [] for task [SqlMapClient operation]
    Code:
    2007-07-13 02:19:23,390 main
     [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
    I've successfully mapped other objects using iBATIS and the insert statements are pretty much straight forward. The only thing that is different in this case is that I wasn't using Spring transactions (in fact the tests were not using transactions) in all the other tests I've done and those tests didn't involve BLOBs. Here however, aside from BLOBs, I'm forced to use transactions.
Working...
X