2015-07-21 238 views
1

我陷入了一個麻煩,我無法連接Oracle 11g數據庫表單,我的Spring MVC應用程序。 我得到的錯誤是Spring JDBC連接問題 - 無法從底層數據庫獲取連接

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database! 

也, 在堆棧跟蹤,我發現了無差錯

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver 

如果你能幫助我解決這個問題,這將是一個偉大的幫幫我。 我提供我的配置和編碼詳情如下:

默認-servlet.xml中

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
    destroy-method="close"> 
    <property name="driverClass" value="${jdbc.driverClassName}" /> 
    <property name="jdbcUrl" value="${jdbc.url}" /> 
    <property name="user" value="${jdbc.username}" /> 
    <property name="password" value="${jdbc.password}" /> 
    <property name="maxPoolSize" value="${jdbc.maxPoolSize}" /> 
    <property name="minPoolSize" value="${jdbc.minPoolSize}" /> 
    <property name="maxStatements" value="${jdbc.maxStatements}" /> 
    <property name="testConnectionOnCheckout" value="${jdbc.testConnection}" /> 
</bean> 

<bean id="userAuthenticationRepository" 
      class="com.era.repository.impl.UserAuthenticationRepositoryImpl"> 

    <property name="dataSource" ref="dataSource" /> 
</bean> 

UserAuthenticationRepositoryImpl.java

@Repository 

公共類UserAuthenticationRepositoryImpl實現UserAuthentic ationRepository {

@Qualifier("dbDataSource") 
private DataSource dataSource; 

public void setDataSource(DataSource dataSource) { 
    this.dataSource = dataSource; 
} 


public User getUserAuthentication(User userToBeAuthenticated) { 
    // TODO Auto-generated method stub 
    String query = "select id, name, role from User where login ="; 
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); 
    StringBuilder queryString = new StringBuilder(); 
    queryString.append(" SELECT ") 
          .append("*") 
          .append(" FROM table_name ") 
          .append(" WHERE login = ? "); 
       Object[] parameterList = { userToBeAuthenticated.getLogin() }; 
       SqlRowSet dataRow = jdbcTemplate.queryForRowSet(queryString.toString(), parameterList); 

       if (dataRow.next()) { 
        System.out.println("Query executed successfully"); 
       } 
    return null; 
} 

enter image description here enter image description here

回答

2

當你正在使用maven,這裏需要注意不能直接獲得Oracle驅動程序罐子.m2由於許可證限制,所以你可能需要手動下載和把它放到你的倉庫中。你可能會發現這個link有幫助。

+1

這個鏈接確實有幫助。非常感謝。 – user3378974