org.postgresql.util.PSQLException:列索引超出范围:3,列数:2

时间:2015-01-15 14:02:45

标签: java postgresql spring-security

我决定通过使用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语法有什么问题?

1 个答案:

答案 0 :(得分:8)

Spring Security期望用户查询中的三列按顺序:

  1. 用户名
  2. 密码
  3. enabled(boolean)
  4. 你没有最后一个。如果你没有等同于&#34;启用&#34;在您的数据库中,您可以使用TRUE常量。