Incentancy
2018-10-24 22:20:02 +08:00
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<html>
<body>
<h2>Hello World!</h2>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/oop", "root", "root");
Statement stat = conn.createStatement();
String sql = "INSERT INTO student(stu_id, stu_name, gender) VALUES ('20181024', '小明', '男')";
int i = stat.executeUpdate(sql);
//out.println("成功添加"+i+"行");
stat.close();
conn.close();
%>
</body>
</html>
以上是代码。
以下是部分报错信息:
...
javax.servlet.ServletException: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '20181024' for key 'PRIMARY'
...
同样的代码在 Eclipse 上就没有出这个问题,请问这是为什么???