异常记录以及解决方法(第一篇)
遇到的异常以及解决方法!
文章目录:
java.lang.ExceptionInInitializerError
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)
java.lang.NullPointerException
org.apache.jasper.JasperException: An exception occurred processing JSP page [/WEB-INF/jsp/.....]
spring+mybatis错误:com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
MySQL运行SQL文件时(全面,改成time):check the manual that corresponds to your MySQL server version for the righ
java.lang.ExceptionInInitializerError
初始化错误
出现问题原因:
在读取德鲁伊连接池的properties配置文件时未读取到
我的文件名为dbcp.properties
解决方法:
修改文件名为druid.properties
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)
数据库异常
出现问题原因:使用JDBC工具类修改数据时未传入sql语句,方法无法找到可变参数(?)
解决方法:传入sql语句并检查形参与可变参数是否一一对应。
java.lang.NullPointerException
空指针异常
出现原因:查询数据时实体类的属性与数据的字段名不匹配,查不到数据,导致遍历时出现异常
解决方法:修改数据库字段名或在sql语句的字段名后面添加as 实体类的属性名
Caused by: java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
非法状态异常
出现原因:文件上传时服务器无法读取文件的类型(Content-Type)
解决方式:在相应的Servlet添加@MultipartConfig注解
org.apache.jasper.JasperException: An exception occurred processing JSP page [/WEB-INF/jsp/.....]
出现原因:使用EI表达式key,取值对象名或者属性错误,前端无法读取
解决方式:检查报错行的key,取值对象名或者属性
Cause: org.apache.ibatis.binding.BindingException:Parameter 'name' not found.Available parameters are [arg1, arg0, param1, param2]
出现原因:默认情况下我们传递的参数会被封装成一个map
- 解决方式:传入参数时第一个写#{param1},第二个写#{param2}
- 解决方式:定义接口时添加@Param注解
spring+mybatis错误:com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
严重: create connection SQLException, url: jdbc:mysql://192.168.211.129:3306/spring_db?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false, errorCode 1045, state 28000java.sql.SQLException: Access denied for user ''@'192.168.211.1' (using password: YES)
我的解决方式:
将db.propertise文件和spring配置文件中的driver, url, password, username改为jdbc.driver, jdbc.url, jdbc.password, jdbc.username
MySQL运行SQL文件时(全面,改成time):check the manual that corresponds to your MySQL server version for the righ
出现原因:使用Navicat premium工具无论是datetime还是time把datetime(0),时间后面都会带“(0)”
解决方法:把datetime(0)全替换成datetime或time(0)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.blb.est.mapper.UsersMapper.getUserNameAndAccount
解决方法:检查一下四点
1.MapperScan
2.mybatis-plus
mapper-location
3.xml文件名与接口名不同
4.mapper.java中的方法名跟xxmapper.xml中的id名不同
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)