1.配置监听
这里假定CDB数据库名为ORCL,PDB在CDB下面名称为PDBORCL
listener.ora添加(#后面为注释,不要添加进去)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(SID_NAME = ORCL) #这里是SID名
)
(SID_DESC =
(GLOBAL_DBNAME = PDBORCL)#这里是PDB数据库名
(SID_NAME = ORCL) #这里是SID名
)
)
tnsname.ora添加
PDBORCL=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT =1521))
)
(CONNECT_DATA =
(SERVICE_NAME = PDBORCL) #这里是PDB数据库名
)
)
2.重启监听(需要管理员权限)
lsnrctl reload
重启监听也可以用下面的代码:
停止监听
lsnrctl stop
启动监听
lsnrctl start
3.检查JDBC代码
注意:连接PDB时,1521端口号后面不是冒号:,而是斜线/
例如
String url = "jdbc:oracle:thin:@//localhost:1521/pdborcl";