簡體   English   中英

在本地主機上連接Oracle時出錯:無法獲得JDBC連接?

[英]Error connecting Oracle on localhost: Could not get JDBC Connection?

我正在嘗試使用Eclipse從Web應用程序連接Oracle數據庫。 但是我得到了錯誤:org.springframework.jdbc.CannotGetJdbcConnectionException:無法獲取JDBC連接;

我用下面的代碼:

public static void initDB(){
    try {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        ds.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
        ds.setUsername("mybank");
        ds.setPassword("123456");

        jdbcTemplate  = new JdbcTemplate(ds); // throw exceptiong after this line
        isConnected = true;
        initSystemPros();
    } catch (Exception e) {
        System.err.println("Cannot connect to DataBase");
        isConnected = false;
    }
}

例外:

INFO: Server startup in 11564 ms 
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) at 
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtil‌​s.java:80) at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382) at 
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)

我嘗試使用SQL Developer使用上述設置創建連接並成功。 你知道錯在哪里嗎?

謝謝,問候

確保xe是您的Service Name

如果連接成功,但是您有此異常SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) at

您必須具有不兼容的JDBC版本,請安裝正確的版本: http : //www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM