当前位置: 代码迷 >> XML/SOAP >> ibatis中xml有关问题
  详细解决方案

ibatis中xml有关问题

热度:562   发布时间:2013-12-30 14:16:08.0
ibatis中xml问题。

提示错误:
javax.servlet.ServletException: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/product/user/Users.hbm.xml.  
--- The error occurred while applying a parameter map.  
--- Check the updateUsers-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 'where UserId=2' at line 1 org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
com.product.servlet.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:36)


root cause 

好像是更新已有信息那一段有语法错误,但是感觉没错啊。。找了好久 求指点
我是要实现从页面中输入数据,来更新数据库信息
下面是xml文件。。

<?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 namespace="Users">

  <typeAlias alias="users" type="com.product.user.Users"/>
  

  
  <select id="getUserByAccount" resultClass="users" parameterClass="java.lang.String">
    SELECT
      UserId,
      UserName,
      Account,
      Password
    FROM Users where Account=#account#
  </select>
  
  <!-- 获取所有用户信息 -->
   <select id="getUsersList" resultClass="users" >
    SELECT
      UserId,
      UserName,
      Account,
      password
    FROM Users order by UserId desc
  </select>
  
  <!-- 更新已有信息 -->
  <update id="updateUsers" parameterClass="Users">
  update Users
      set
      UserName=#userName#,
      Account=#account#,
      password=#password#
    where UserId=#userId#
  </update>
  
  <!--修改个人信息-->
  <insert id="insertUsers" parameterClass="Users">
    <!-- insert into Users
     (UserName,Account,password,UserId)
     values
     (#userName#,#accout#,#password#,#userId#);-->
  </insert>

</sqlMap>

------解决方案--------------------
更新已有信息方法按照下面例子写全,引用参数类的路劲写全等改改。

<update id="updateRecord"
parameterClass="com.framework.mapping.InfoType">
<![CDATA[ update infoType set id = #id#]]>
<dynamic>
<isNotNull property="name" prepend=",">
<![CDATA[ name = #name# ]]>
</isNotNull>
<isNotNull property="parentId" prepend=",">
<![CDATA[ parentId = #parentId# ]]>
</isNotNull>
<isNotNull property="sort" prepend=",">
<![CDATA[ sort = #sort# ]]>
</isNotNull>
<isNotNull property="describe" prepend=",">
<![CDATA[ describe = #describe# ]]>
</isNotNull>
</dynamic>
<![CDATA[ where id = #id# ]]>
</update>

------解决方案--------------------
只是规范一下写法而已,防止空格、换行sql拼接等不必要错误罢了。
  相关解决方案