报错集
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
原因
使用PreparedStatement时,like子句的问号多打了单引号。
String
修改
将单引号去掉。
String
java.sql.BatchUpdateException: Duplicate entry '运营部10' for key 'department_name'
原因
dept = new Departments();没有放到循环中,导致添加的都是同一个对象,触发唯一性约束。
List
修改
将dept = new Departments();放到循环中
List
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
原因
缺少commons-logging-1.2.jar包
修改
导入commons-logging-1.2.jar包
警告:Establishing SSL connection without server's identity verification is not recommended
WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
原因是MySQL在高版本需要指明是否进行SSL连接。 在mysql连接字符串url中加入ssl=true或者false即可:
<property
The reference to entity "characterEncoding" must end with the ';' delimiter.
原因:“&”,在xml中这个是读不出的,正确写法将“&”转义“&”:
jdbc:mysql://localhost:3306/photo?useUnicode=true&characterEncoding=UTF-8
&characterEncoding=UTF-8
前言不允许有内容
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
mybatis绑定方案
Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.trf.mapper.UserMapper.selALL
原因,接口方法名与配置id不一致
org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.trf.mapper.StudentMapper.
原因,mapper配置文件中的resultMap属性没有填写
Error updating database. Cause: java.lang.NumberFormatException: For input string: "{0=null}"
在标签中接收参数的时候test中去掉#{}直接写上参数的名称就可以了也是一样
java.lang.NoSuchMethodException: com.trf.servlet.DeptServlet.addDept(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
现象:BaseServlet中已经正确取到方法名,但是仍然报错
原因:DeptServlet中的addDept方法写成了protected而不是public
解决:改成public即可
Invalid bound statement (not found)
原因
- 检查xml文件所在package名称是否和Mapper interface所在的包名
<mapper namespace="me.tspace.pm.dao.UserDao">
mapper的namespace写的不对!!!注意修改。
- UserDao的方法在UserDao.xml中没有,然后执行UserDao的方法会报此
- UserDao的方法返回值是List,而select元素没有正确配置ResultMap,或者只配置ResultType!
- 如果你确认没有以上问题,请任意修改下对应的xml文件,比如删除一个空行,保存.问题解决
- 看下mapper的XML配置路径是否正确
Cause: java.lang.ClassNotFoundException: Cannot find class: employee
现象:服务器正常启动,只要调用Dao层就会报错
原因:别名配置不正确

解决,正确配置别名包

org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'com.trf.dao.EmployeeDao' but found 'com.trf.dao.Employee'.
现象:服务器正常启动,只要调用Dao层就会报错
原因:命名空间配置错误

解决:正确配置命名空间
