我正在进行一个涉及 Spring MVC、Spring Security 和 DerbyDB 的学校项目。
我有一个无法解决的问题,我需要帮助,在此先感谢。
这是我尝试使用真实用户登录时的消息(打印在网页上):
Your login attempt was not successful, try again.
Reason: PreparedStatementCallback; bad SQL grammar [select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?]; nested exception is java.sql.SQLException: Column '3' not found.
这是控制台中的消息:
SQL error codes for 'Apache Derby' found
2013-10-22 16:07:16 [DEBUG] SQLErrorCodeSQLExceptionTranslator:283 - Unable to translate SQLException with SQL state 'S0022', error code '0, will now try the fallback translator
2013-10-22 16:07:16 [DEBUG] SQLStateSQLExceptionTranslator:95 - Extracted SQL state class 'S0' from value 'S0022'
2013-10-22 16:07:16 [DEBUG] UsernamePasswordAuthenticationFilter:346 - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: PreparedStatementCallback; bad SQL grammar [select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?]; nested exception is java.sql.SQLException: Column '3' not found.
2013-10-22 16:07:16 [DEBUG] UsernamePasswordAuthenticationFilter:347 - Updated SecurityContextHolder to contain null Authentication
我的数据源bean:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:/home/couty/capDB;create=true" />
<property name="username" value="root" />
<property name="password" value="password" />
</bean>
spring-security.xml :
<http auto-config="true">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query='select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?'/>
<!-- authorities-by-username-query="select u.login, ur.role from User u, UserRole ur where u.id = ur.user_id and u.login =? " -->
</authentication-provider>
</authentication-manager>
如您所见:我在访问 /welcome 页面时尝试登录。我使用的 JDBC 驱动程序是 DERBY,而不是 ORACLE。为什么 ?因为我已经参加了德比战,而甲骨文似乎很难抓住......我不知道它有什么变化。