zhuqibs
作者zhuqibs·2020-04-30 09:28
软件开发工程师·Adidas

Oracle 个人技巧 -- jdbc 驱动写法

字数 2181阅读 809评论 0赞 3

格式一: Oracle JDBC Thin using a ServiceName:
jdbc:oracle:thin:@//:/
Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE

注意这里的格式,@后面有//, 这是与使用SID的主要区别。
这种格式是Oracle 推荐的格式,因为对于集群来说,每个节点的SID 是不一样的,但是SERVICE_NAME 确可以包含所有节点。

格式二: Oracle JDBC Thin using an SID:
jdbc:oracle:thin:@::
Example: jdbc:oracle:thin:192.168.2.1:1521:X01A

Note: Support for SID is being phased out. Oracle recommends that users switch over to usingservice names.

格式三:Oracle JDBC Thin using a TNSName:
jdbc:oracle:thin:@
Example: jdbc:oracle:thin:@GL

Note:
Support for TNSNames was added in the driver release 10.2.0.1

jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)
(ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service)
(FAILOVER_MODE = (TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5))
))

If you have to connect to oracle RAC (Real Application Cluster) using JDBC with thin driver, the classic url:
jdbc:oracle:thin:@:1521:
doesn’t work and you get the error ORA – 12505.
Instead, you must use this url:
jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)
(ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service)))

Specifier Supported Drivers Example
Oracle Net connection descriptor Thin, OCI
Thin, using an address list:

url="jdbc:oracle:thin:@(DESCRIPTION=
(LOAD_BALANCE=on)
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=service_name)))"

OCI, using a cluster:

"jdbc:oracle:oci:@(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=cluster_alias)
(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service_name)))"
Thin-style service name Thin
"jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename"
LDAP syntax Thin
"jdbc:oracle:thin:@ldap://ldap.example.com:7777/sales,cn=OracleContext,dc=com"
Bequeath connection OCI Empty. That is, nothing after @

"jdbc:oracle:oci:scott/tiger/@"
TNSNames alias Thin, OCI OracleDataSource ods = new OracleDataSource();
ods.setTNSEntryName("MyTNSAlias");

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

3

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广