调用addUser的接口出错
来源:11-3 使用mybatis实现添加数据和idea的debug操作

qq_慕田峪8248634
2021-12-31
2021/12/31
15:26 com.intellij.execution.ExecutionException: Exception in thread “main” java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.database.remote.RemoteJdbcServer.main(RemoteJdbcServer.java:14)
2021-12-31 17:21:15.872 [http-nio-8899-exec-1] ERROR o.a.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:
Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘name’ cannot be null
The error may exist in file [D:\AutoTest\Chapter13\target\classes\mapper\mysql.xml]
The error may involve com.course.addUser-Inline
The error occurred while setting parameters
SQL: insert into user(id,name,age,sex) values(?,?,?,?)
Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘name’ cannot be null
; Column ‘name’ cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column ‘name’ cannot be null] with root cause
java.sql.SQLIntegrityConstraintViolationException: Column ‘name’ cannot be null
1回答
-
大周
2022-01-04
上边的错误一共有两个问题,第一个问题是数据库连接的驱动,应该是版本对应的问题。 com.mysql.jdbc.Driver改成com.mysql.cj.jdbc.Driver这样试试看
第二个问题是你sql中name这一列的值不能为空,其实你可以把id去掉,因为在数据库中,id一般都是自动生成的。
022022-07-20
相似问题