`
thinktothings
  • 浏览: 784608 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Connection refused: connect

阅读更多

orcl.16.50.110 是安装数据库时设的全局数据库名

 

原因:url没有用全局数据库名 

 

Caused by: java.net.ConnectException: Connection refused: connect

 

 

 

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;

class JDBCVersion {
 public static void main(String args[]) throws SQLException {
  OracleDataSource ods = new OracleDataSource();
  ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/orcl");
  Connection conn = ods.getConnection();
  // Create Oracle DatabaseMetaData object
  DatabaseMetaData meta = conn.getMetaData();
  // gets driver info:
  System.out.println("JDBC driver version is " + meta.getDriverVersion());
 }
}

 

 

Exception in thread "main" java.sql.SQLException: The Network Adapter could not establish the connection
 at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
 at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
 at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
 at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
 at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
 at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
 at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
 at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
 at JDBCVersion.main(JDBCVersion.java:9)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
 at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
 at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
 at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
 at oracle.net.ns.NSProtocol.connect(NSProtocol.java:353)
 at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
 at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
 ... 8 more
Caused by: java.net.ConnectException: Connection refused: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
 at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
 at java.net.Socket.connect(Socket.java:529)
 at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
 at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
 at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
 ... 13 more

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

改为

 

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;

class JDBCVersion {
 public static void main(String args[]) throws SQLException {
  OracleDataSource ods = new OracleDataSource();
  ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/orcl.16.50.110");
  Connection conn = ods.getConnection();
  // Create Oracle DatabaseMetaData object
  DatabaseMetaData meta = conn.getMetaData();
  // gets driver info:
  System.out.println("JDBC driver version is " + meta.getDriverVersion());
 }
}

 

 

打印出来的:JDBC driver version is 11.2.0.1.0

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics