【问题标题】:org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2org.postgresql.util.PSQLException:列索引超出范围:3,列数:2
【发布时间】:2015-03-13 22:43:37
【问题描述】:

我决定通过使用spring security 和数据库添加身份验证来修改我的应用程序。在我使用 XML 中的 userpassword 进行普通身份验证之前。效果很好。

我的authentication-manager 看起来像这样

<authentication-manager>
    <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"
        users-by-username-query="select username, password from pmc.username_password where username=?;"
        authorities-by-username-query="select a.username, b.role from pmc.username_password a, pmc.username_role b where a.username = b.username and a.username=?;" />
    </authentication-provider>
</authentication-manager>

但是当我尝试进行身份验证时出现异常

org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select u
sername, password from pmc.username_password where username=?;]; The column index is out of range: 3, number of columns: 2.;
 nested exception is org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2.

我在 XML 文件中的 sql 语法有什么问题?

【问题讨论】:

    标签: java postgresql spring-security


    【解决方案1】:

    Spring Security 需要用户查询中的三列,按顺序:

    1. 用户名
    2. 密码
    3. 启用(布尔值)

    你没有最后一个。如果您的数据库中没有“启用”的等效项,则可以使用TRUE 常量。

    【讨论】:

      猜你喜欢
      • 2012-08-24
      • 2023-03-25
      • 2015-02-27
      • 1970-01-01
      • 2018-05-28
      • 2021-05-25
      • 2013-07-16
      • 1970-01-01
      • 2021-05-25
      相关资源
      最近更新 更多