2013-10-22 157 views
0

我在一個涉及Spring MVC,Spring Security和DerbyDB的學校項目。Spring Security和DerbyDB(javaDB)

我有一個問題,我無法解決,我需要幫助,在此先感謝。

這裏的消息時,我嘗試登錄,與真實的用戶(打印的網頁上):

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

的彈簧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> 

正如您所看到的: 我試圖在訪問/歡迎頁面時登錄。 我使用的JDBC驅動程序是DERBY,而不是ORACLE。爲什麼?因爲我已經有德比了,甲骨文似乎很難被抓住......我不知道它會發生什麼變化。

+0

下面是關於如何獲得更多的信息,你的的SQLException的一些建議:http://wiki.apache.org/db-derby/UnwindExceptionChain –

+0

嗨,謝謝,我會在我的應用程序中使用它。 但是,由於這裏的請求是由Spring Security實現的,我不知道該如何捕獲sql異常... – ogdabou

+0

嘗試使用「ij」工具直接連接到數據庫並直接發出違規的SQL語句,看看你是否得到了更好的錯誤顯示,給你更多的線索。或者,使用derby.language.logStatementText = true在derby.log中獲取更多信息 –

回答

0

我相信你必須添加一個額外的列「啓用」來查詢。所以像這樣的東西 - 選擇來自theaterDB的LOGIN,PASSWORD,「用戶」,其中LOGIN =?。

我有同樣的問題,這個工作在我的情況;)