gpt4 book ai didi

mysql - 什么是 org.h2.jdbc.JdbcSQLDataException : Invalid value "3" for parameter "columnIndex" [90008-200]?

转载 作者:行者123 更新时间:2023-12-04 09:16:25 27 4
gpt4 key购买 nike

当我遇到下面的错误消息时,我正在尝试使用 JDBC 身份验证来进行 Spring 安全。我正在尝试将 User 类中的所有电子邮件和密码注册为有效登录。我不确定我的 sql 语句或我的 User 类是否有问题。任何帮助,如果赞赏!

Caused by: org.h2.jdbc.JdbcSQLDataException: 
Invalid value "3" for parameter "columnIndex" [90008-200]
Spring 安全
    @Autowired      
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
// To find logins in the h2 database
.dataSource(dataSource)
.usersByUsernameQuery("select email, password " +
"from User " +
"where email = ?")
.authoritiesByUsernameQuery("select email, role " +
"from User " +
"where email =?");

}
用户类
     @Entity
public class User {
private String firstName;
private String lastName;
@Size(min = 6, message ="Enter at least 6 characters")
@ValidPassword
private String password;
private String matchingPassword;
private String passportNumber;
private String address;
private String phoneNumber;
@ValidEmail
private String email;

// Mark as primary key
@Id
// Will be auto generated
@GeneratedValue
private long id;
private String role;



public User(@NotNull String firstName, @NotNull String lastName,
@Size(min = 6, message = "Enter at least 6 characters") @NotNull String password,
@NotNull String passportNumber, @NotNull String address, @NotNull String phoneNumber, String email,
String role) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
this.passportNumber = passportNumber;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = email;
this.role = role;
}

@Override
public String toString() {
return "User [firstName=" + firstName + ", lastName=" + lastName + ", password=" + password
+ ", matchingPassword=" + matchingPassword + ", passportNumber=" + passportNumber + ", address="
+ address + ", phoneNumber=" + phoneNumber + ", email=" + email + ", id=" + id + ", role=" + role + "]";
}

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}





public String getPassword() {
return password;
}


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


public String getMatchingPassword() {
return matchingPassword;
}


public void setMatchingPassword(String matchingPassword) {
this.matchingPassword = matchingPassword;
}


public String getFirstName() {
return firstName;
}


public void setFirstName(String firstName) {
this.firstName = firstName;
}


public String getLastName() {
return lastName;
}


public void setLastName(String lastName) {
this.lastName = lastName;
}


public String getPassportNumber() {
return passportNumber;
}


public void setPassportNumber(String passportNumber) {
this.passportNumber = passportNumber;
}


public String getAddress() {
return address;
}


public void setAddress(String address) {
this.address = address;
}


public String getPhoneNumber() {
return phoneNumber;
}


public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}



public void setId(long id) {
this.id = id;
}


protected User() {

}

public long getId() {
return id;
}

}
编辑:这个问题的答案标记在下面

最佳答案

  • Spring security 预计 usersByUserName 有 3 列询问。如果您没有指定,这里是使用的默认查询。
  •     public static final String DEF_USERS_BY_USERNAME_QUERY 
    = "select username, password, enabled from users where username = ?";

  • 因此,如果您没有用于启用和禁用用户的此类列,请使用以下查询
  •     select email, password, 'true' as enabled from User where email = ?
    引用
    https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.html

    关于mysql - 什么是 org.h2.jdbc.JdbcSQLDataException : Invalid value "3" for parameter "columnIndex" [90008-200]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63191617/

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