gpt4 book ai didi

java - 该语句被中止,因为它会导致唯一或主键约束或唯一索引中的重复键值由

转载 作者:行者123 更新时间:2023-11-29 00:13:22 25 4
gpt4 key购买 nike

 public void adduser(UserBean user) throws SQLException{
String query = "INSERT INTO usersInformation ( username, " +
"password, email ) VALUES ( '" + user.getUsername() + "', '" +
user.getPassword() + "', '" + user.getEmail() + "' )" ;
statement.execute(query);
}

我在这一行得到这个异常:statement.execute(query) 任何人都可以帮助我吗?异常:已中止,因为它会导致在“USERSINFORMATION”上定义的“SQL140525011235350”标识的唯一或主键约束或唯一索引中出现重复键值。

[编辑]

这是我的 bean 类

public class UserBean {

private String username;
private String password;
private String email;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}

index.jsp(index.jsp 的邮件部分)

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id = "userbean" class = "newpackage.UserBean" />
<jsp:useBean id = "userdatabean" class = "newpackage.UserDataBean" />

<jsp:setProperty name ="userbean" property="*"/>
<% userdatabean.adduser(userbean); %>

最佳答案

从异常详细信息可以清楚地看出该语句在主键字段中输入了重复值,因此违反了唯一键约束。检查您的数据并相应地插入

关于java - 该语句被中止,因为它会导致唯一或主键约束或唯一索引中的重复键值由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23852270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com