使用瘦驱动程序的Oracle 12c数据库连接抛出IO错误 [英] Oracle 12c database connection using thin driver throws IO error

查看:220
本文介绍了使用瘦驱动程序的Oracle 12c数据库连接抛出IO错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循《 JDBC开发人员指南》,并尝试使用简短的Java程序测试JDBC瘦驱动程序连接.

I'm following the JDBC Developer's Guide and trying to test the JDBC thin driver connection using a short java program.

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:1522: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());
}
} //<host>:<port>:<service>

我尝试了所有可能的<host>:<port>:<service>组合,但仍然得到java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

I've tried every possible <host>:<port>:<service> combination but still get a java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

我已经使用教程中包含的另一程序成功测试了OCI驱动程序.我的应用程序将使用瘦驱动程序连接到数据库,因此我的挫败感是.... clipinging.

I've successfully tested the OCI driver using another program included in the tutorial....but can't get this one to work. My application will be using the thin driver to connect to the database so my frustration level is....climbing.

感谢您的帮助.

推荐答案

也许以下注释可以解释为什么您需要服务名称而不是URL中的SID.

Maybe following comments could explain why you need the sevice name instead of the SID in the URL.

  • Oracle JDBC FAQ 提到SIDs will be cease to be supported in one of the next few releases of the database

Oracle JDBC开发者指南提及Always connect to a service. Never use instance_name or SID because these do not direct to known good instances and SID is deprecated

Oracle 2天+ Java开发人员教程提及语法jdbc:oracle:driver_type:[username/password]@//host_name:port_number:SID,它似乎是SID和服务名URL的混合(在其他文档和您的工作示例之后)

the Oracle 2 day + Java developer tutorial mention the syntax jdbc:oracle:driver_type:[username/password]@//host_name:port_number:SID which seems to be a mixture of SID and service name URL (following the other documents and your working example)

OracleDriver >仅提及SID语法

in contrast the javadoc for OracleDriver mention only the SID syntax

Oracle FAQ Wiki 提到两种语法

.

jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SID
jdbc:oracle:thin:[USER/PASSWORD]@//[HOST][:PORT]/SERVICE

这篇关于使用瘦驱动程序的Oracle 12c数据库连接抛出IO错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆