org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
### The error may involve com.mybatis.po.DeptMapper.addDept-Inline
### The error occurred while setting parameters
### SQL: insert into dept values(?,?,?);
### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
at com.mybatis.test.DeptTest.main(DeptTest.java:20)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:947)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
... 2 more
测试代码:--------------------------------------------------------------------------------------------、
String resource = "configuration.xml";
Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(reader);
SqlSession session=factory.openSession();
int count= session.insert("com.mybatis.po.DeptMapper.addDept",new Dept(5, "张三", "北京"));
System.out.println(count);
XML文件:------------------------------------------------------------------------------------------
<insert id="addDept" parameterType="com.mybatis.po.Dept">
insert into dept values(#{deptno},#{dname},#{loc});
</insert>
4 个解决方案
#1
是不是,乱码了
#2
没有用页面啊 就是在测试类里面测试的
#3
insert into dept values(${deptno},${dname},${loc});
把sql先改成这样,看结果sql是怎么个
把sql先改成这样,看结果sql是怎么个
#4
解决了大家 写在XML里面的SQL语句不能有分号结尾
#1
是不是,乱码了
#2
没有用页面啊 就是在测试类里面测试的
#3
insert into dept values(${deptno},${dname},${loc});
把sql先改成这样,看结果sql是怎么个
把sql先改成这样,看结果sql是怎么个
#4
解决了大家 写在XML里面的SQL语句不能有分号结尾