jdbc连接oracle时:
jdbc连接数据库的时候,需要使用数据库的sid_name(数据库的对内的实例名称),而不是数据库的services_name(数据库对外服务名称).而使用plsql连接数据库的时候,只需要数据库的services_name即可,所以修改连接字符串中的services_name 为sid_name.
查询sid_name的方法select INSTANCE_NAME from v$instance;
查询service_name:
show parameter service;
ps:都是在以管理的员的身份下查询.
jdbc连接oracle三种方式:
格式一: Oracle JDBC Thin using a ServiceName:
jdbc:oracle:thin:@//<host>:<port>/<service_name>
Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE
注意这里的格式,@后面有//, 这是与使用SID的主要区别。
这种格式是Oracle 推荐的格式,因为对于集群来说,每个节点的SID 是不一样的,但是SERVICE_NAME 确可以包含所有节点。
格式二: Oracle JDBC Thin using an SID:
jdbc:oracle:thin:@<host>:<port>:<SID>
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:@<TNSName>
Example: jdbc:oracle:thin:@GL
Note:
Support for TNSNames was added in the driver release 10.2.0.1