Java.sql.SQLSyntaxErrorException:ORA-00971:アノテーションを使用して動的SQLを完了するときにSETキーワードがありません



Java Sql Sqlsyntaxerrorexception



Java.sql.SQLSyntaxErrorException:ORA-00971:アノテーションを使用して動的SQLを完了するときにSETキーワードがありません

例外情報:



### The error may involve com.baizhi.dao.BookDao.uodateBook-Inline ### The error occurred while setting parameters ### SQL: update t_book setbookname=?,author=?,status=? ### Cause: java.sql.SQLSyntaxErrorException: ORA-00971: missing SET keyword at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy16.uodateBook(Unknown Source) at com.baizhi.service.impl.BookServiceImpl.updateBook(BookServiceImpl.java:119) at com.baizhi.action.BookAction.updateBook(BookAction.java:127) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)

あなたはあることがわかります

setbookname =?、明らかにこれは、setとbooknameの間に分離がないためです。対応する方法を確認してください。コードは次のとおりです。



​ public String updateProvider(Book b){ //You can see that set and bookname are connected together because there is no space after set String sql='update t_book set' if (b.getBookname()!=null){ sql+='bookname=#{bookname},' } if (b.getPrice()!=null){ sql+='price=#{price},' } if (b.getAuthor()!=null){ sql+='author=#{author},' } if (b.getNum()!=null){ sql+='num=#{num},' } if (b.getDescribe()!=null){ sql+='describe=#{describe},' } if (b.getStatus()!=null){ sql+='status=#{status}' } if(sql.endsWith(',')){ sql.substring(0,sql.length()-1) } System.out.println(sql) return sql } ​

そのため、セットの後にスペースを追加する必要があります。