Code Bye

使用数据库连接池遇到Oracle连接不上

我使用sqlplus和PLSQLDeveloper连接本地数据库都没有问题,但是使用JDBC就连接不上了,不知道哪里问题。请懂的人指教下,感激不尽!

public class ConnectionFactory {
	private static BasicDataSource bds;
	private static String driverClassName = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:oracle:thin:@localhost:1521:orcl";
	private static String username = "fcs";
	private static String password = "123";
	private ConnectionFactory(){

	}
	public static BasicDataSource getBs(){
		if(null == bds){
			bds = new BasicDataSource();
			bds.setDriverClassName(driverClassName);
			bds.setUrl(url);
			bds.setUsername(username);
			bds.setPassword(password);
			bds.setMaxActive(10);
		}
		return bds;
	}
	public static void main(String[] args) {
		try {
			System.out.println(ConnectionFactory.getBs().getConnection().isClosed());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

报错
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.wistron.DB.ConnectionFactory.main(ConnectionFactory.java:30)
Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:547)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
… 3 more

自己先顶下。

15分
把listener.ora贴出来看看
引用

把listener.ora贴出来看看

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = PC-xxxxx.com)(PORT = 1521))
    )
  )

把host(PC-xxxxx.com)改为localhost或者127.0.0.1再试试

10分
HOST改下localhost
引用

把host(PC-xxxxx.com)改为localhost或者127.0.0.1再试试

引用

HOST改下localhost

改了还是不行啊

引用 6 楼 u013283727 的回复:
引用

把host(PC-xxxxx.com)改为localhost或者127.0.0.1再试试

Quote:

HOST改下localhost

改了还是不行啊

把oracle的listener和服务重启下,再看看

引用

把oracle的listener和服务重启下,再看看

新错误:

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))))
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.wistron.DB.ConnectionFactory.main(ConnectionFactory.java:30)
Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:547)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
… 3 more

引用 8 楼 u013283727 的回复:
引用

把oracle的listener和服务重启下,再看看

新错误:

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))))
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.wistron.DB.ConnectionFactory.main(ConnectionFactory.java:30)
Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:547)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
… 3 more

你现在这种情况,用plsql还能连接上啊?

引用

你现在这种情况,用plsql还能连接上啊?

现在plsql不行了,sqlplus还好。

引用

引用

    你现在这种情况,用plsql还能连接上啊?

现在plsql不行了,sqlplus还好。

PLSQL中没有选择database可以连上。


15分
关闭防火墙试试
引用

关闭防火墙试试

都关了。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用数据库连接池遇到Oracle连接不上