--Can someone help me?I tried other way to fix this error.but failed.1.1Envirment:Hardware:Windows10+JDK 1.8;Software:Java+Eclipse+Mybatis+maven3.6+tomcat8.0+Postgresql 10.6;1.2 Project structure
1.3 jar packageasm-3.3.1.jarcglib-2.2.2.jarcommons-logging-1.1.1.jarjavassist-3.17.1-GA.jarlog4j-1.2.17.jarlog4j-api-2.0-rc1.jarlog4j-core-2.0-rc1.jarmybatis-3.2.7.jarmybatis-spring-1.2.1.jarmysql-connector-java-5.1.20.jarpostgresql-42.2.5.jre7.jarslf4j-api-1.7.5.jarslf4j-log4j12-1.7.5.jar2.problem:when i run the test,the error come,I really need some advices.hrer is my code:3.User.javapackage com.ironxi.entity;public class User {private int id;private String name;private String password;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassward(String password) {this.password = password;}@Overridepublic String toString() {return "User [id=" + id + ", name=" + name + ", password=" + password + "]";}}4.UserMapping.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"<mapper namespace="com.ironxi.entity.UserMapper"><select id="selectUser" resultType="com.ironxi.entity.User">SELECT * FROM public.use where id=#{id}</select><insert id="addUser" parameterType="com.ironxi.entity.User" useGeneratedKeys="true">INSERT INTO public.use{name,password} VALUES(#{name},#{password})</insert></mapper>5.UserDao.javapackage com.ironxi.dao;import java.io.IOException;import org.apache.ibatis.session.SqlSession;import com.ironxi.entity.User;import com.ironxi.util.MybatisUtil;public class UserDao {/**search*/public User getById(int id) throws IOException{SqlSession session = MybatisUtil.getSession();User user = (User)session.selectOne("com.ironxi.entity.UserMapper.selectUser",1);session.close();return user;}/**add*/public int add(User user) throws IOException{SqlSession session = MybatisUtil.getSession();int result=session.insert("com.ironxi.entity.UserMapper.addUser",user);session.commit();session.close();return result;}}6.Test.javapackage com.ironxi.test;import java.io.IOException;import org.apache.ibatis.session.SqlSession;import com.ironxi.dao.UserDao;import com.ironxi.entity.User;import com.ironxi.util.MybatisUtil;public class Test {public static void main(String[] args) throws IOException {UserDao userDao= new UserDao();//System.out.println(userDao.getById(1));User user=new User();user.setName("SaSon");user.setPassward("12349");System.out.println(userDao.add(user));}}7.mybatis.conf.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN"<configuration><environments default="development"><environment id="development"><transactionManager type="JDBC" /><dataSource type="UNPOOLED"><property name="driver" value="org.postgresql.Driver"/><property name="url" value="jdbc:postgresql://localhost:5432/postgres" /><property name="username" value="postgres" /><property name="password" value="Iron.336" /></dataSource></environment></environments><mappers><mapper resource="com/ironxi/entity/UserMapper.xml" /></mappers></configuration>8.Console:log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"Position: 23### The error may involve com.ironxi.entity.UserMapper.addUser-Inline### The error occurred while setting parameters### SQL: INSERT INTO public.use{name,password} VALUES(?,?)### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"Position: 23at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:154)at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)at com.ironxi.dao.UserDao.add(UserDao.java:21)at com.ironxi.test.Test.main(Test.java:19)Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"Position: 23at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:62)at com.sun.proxy.$Proxy1.execute(Unknown Source)at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)... 3 more
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.