org.postgresql.util.PSQLException:列索引超出范围:3,列数:2 [英] org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2

查看:1159
本文介绍了org.postgresql.util.PSQLException:列索引超出范围:3,列数:2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定通过使用 spring security 和数据库添加身份验证来修改我的应用程序。在我使用XML中的用户密码进行普通身份验证之前。它工作正常。

I decided to modify my application by adding there authentication using spring security and database. Before I was using plain authentication with user and password in XML. It worked fine.

我的身份验证经理看起来像这样

<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>

但是当我尝试进行身份验证时,我有异常

But when I make an attempt to authenticate I've got exception

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 语法有什么问题?

What is wrong in my sql syntax in XML file?

推荐答案

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

Spring Security expects three columns from the user query, in order:


  1. username

  2. 密码

  3. 启用(布尔值)

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

You don't have the last. If you don't have have an equivalent to "enabled" in your database, you can use a TRUE constant.

这篇关于org.postgresql.util.PSQLException:列索引超出范围:3,列数:2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆