org.postgresql.util.PSQLException:列索引超出范围:3,列数:2 [英] org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 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:
- username
- 密码
- 启用(布尔值)
你没有最后。如果您的数据库中没有等效的启用,则可以使用 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屋!