我正在遵循 JDBC 开发人员指南并尝试使用简短的 java 程序测试 JDBC 瘦驱动程序连接。
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
我已经使用教程中包含的另一个程序成功测试了 OCI 驱动程序......但无法让这个程序工作。我的应用程序将使用瘦驱动程序连接到数据库,所以我的挫败感是......攀登。
任何帮助表示赞赏。
也许以下命令可以解释为什么您需要服务名称而不是 URL 中的 SID。
the Oracle JDBC 常见问题解答 http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#05_10提到这一点SIDs will be cease to be supported in one of the next few releases of the database
the Oracle JDBC 开发人员指南 https://docs.oracle.com/database/121/JJDBC/appcontnew.htm#JJDBC29059提到Always connect to a service. Never use instance_name or SID because these do not direct to known good instances and SID is deprecated
the Oracle 2 天 + Java 开发人员教程 https://docs.oracle.com/database/121/TDPJD/getconn.htm#TDPJD138提及语法jdbc:oracle:driver_type:[username/password]@//host_name:port_number:SID
这似乎是 SID 和服务名称 URL 的混合(遵循其他文档和您的工作示例)
相比之下,javadoc为Oracle驱动程序 https://docs.oracle.com/database/121/JAJDB/oracle/jdbc/OracleDriver.html仅提及 SID 语法
the Oracle 常见问题解答维基 http://www.orafaq.com/wiki/JDBC#Thin_driver提及两种语法
.
jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SID
jdbc:oracle:thin:[USER/PASSWORD]@//[HOST][:PORT]/SERVICE
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)