首页 > 解决方案 > 列不能为 Null

问题描述

我有一个错误说:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:列“课程名称”不能为空`

当我将它设置为 Nullable 列时,它将我输入的任何文本存储为 null,我尝试了许多排序规则但没有工作

这是代码:

String coursename = request.getParameter("name");  
String duration = request.getParameter("duration");  

Connection con;
PreparedStatement pst;
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql://localhost/studentms","root","");
pst = con.prepareStatement("insert into course(coursename,duration)values(?,?)");
pst.setString(1, coursename);
pst.setString(2, duration);
pst.executeUpdate();
out.println("Added sucessfully");

标签: javamysqljspexception

解决方案


推荐阅读