请教为什么本机Windows环境下java连接Linux环境下Oracle数据库出错?(注:一下代码连接本机Oracle数据库正常,驱动包为ojdbc14.jar)
以下为java连接Oracle数据库代码,在连接本机Oracle数据库正常
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;public Connection getConnection() {
   try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
 if(con == null || con.isClosed()){
    con = DriverManager.getConnection("jdbc:oracle:thin:@10.216.8.212:1521:NXDC","mw_sys","sys");
  }
        } catch (Exception e) {
  e.printStackTrace();
  System.out.print("连接出异常!");
        }
  return con;
}
连接服务器Oracle异常信息(服务器系统:Linux)
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
10.216.8.212:1521:NXDCat oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:260)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:413)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.oracleconnection.dao.ConnectionManager.getConnection(ConnectionManager.java:15)
at com.oracleconnection.dao.FiveMinutesdt.getFivedt(FiveMinutesdt.java:10)
at com.oracleconnection.dao.FiveMinutesdt.main(FiveMinutesdt.java:27)
连接出异常!java.lang.NullPointerException
at com.oracleconnection.dao.FiveMinutesdt.getFivedt(FiveMinutesdt.java:12)
at com.oracleconnection.dao.FiveMinutesdt.main(FiveMinutesdt.java:27)

解决方案 »

  1.   

    连接windows与linux从代码来说没有任何关系,只是你要确保驱动包是否正确,因为windows下的oracle和linux下的oracle驱动是不同的。
      

  2.   

    java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    The Connection descriptor used by the client was:
    10.216.8.212:1521:NXDC 
    NXDC,这个SID写错了,你的linux的SID是什么就改成那个。
    先在你的机器上命令行下面
    tnsping linux的OracleSID,看看能不能通。
      

  3.   

    java.sql.SQLException: Listener refused the connection with the following error: 
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 
    The Connection descriptor used by the client was: 
    10.216.8.212:1521:NXDC 
      

  4.   

    参考下
    http://hi.baidu.com/bskd/blog/item/069e3ed35d2577073af3cf10.html
      

  5.   

    oracle配置问题,google或百度搜一下,关键字:上面报的错误