我正尝试使用Eclipse从我的Web应用程序连接Oracle数据库。 但我得到了错误:org.springframework.jdbc.CannotGetJdbcConnectionException:无法获得JDBC连接;在localhost上连接Oracle时出错:无法获得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(DataSourceUtils.java:80) at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382) at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
我试图用SQL Developer来创建使用上面的设置和成功的连接。 你知道什么是错的吗?
感谢和问候, 大
那为什么你有2行代码*之后*说的行:*抛出此行后的异常*?hmm,尝试交换行顺序?'isConnected = true; initSystemPros(); jdbcTemplate = new JdbcTemplate(ds);' – Coffee 2014-09-27 15:52:20
您正在隐藏异常消息抛出如何完全异常栈。 – OldProgrammer 2014-09-27 15:54:03
@OldProgrammer - 你的意思是'如何完全异常栈.'咋做? – Coffee 2014-09-27 15:56:22