If the database is not on the local host, you must configure the corresponding tns in $ ORACLE_HOMEnetworkadmintnsnames.ora before the program can access the database through the configured tns
If the database is not on the local host, you must configure the corresponding tns in $ ORACLE_HOME/network/admin/tnsnames. ora before the program can access the database through the configured tns
If the database is not on the local host, it must be in $ Oracle_HOME/network/admin/tnsnames. configure the corresponding tns in ora, and then the program can access the database through the configured tns. However, if java accesses oracle through the thin method, you can use the locally configured tns alias ,, you can also use the tns full resolution name and the full descriptor after the alias equals sign; as follows:
TESTCZ =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = TESTCZ)
)
)
For example.
There are now two databases
Adb. the username and password are adb and adb respectively. The tns name configured on the local host is tns_a and the host;
Bdb. the user name and password are bdb/bdb respectively. The tns name configured on the local host is tns_ B and the host B is located;
Now we need to create a dblink on the adb to connect to the bdb database;
Method 1:
Edit the tnsnames. ora file on host a to configure the tns alias tns_ B OF THE bdb database, as shown below:
Tns_ B =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = dbtestb)
)
)
Create a database connection as follows:
Create database link
Connect to bdb identified by bdb
Using 'tns _ B ';
Method 2:
If you do not have the permission to modify tnsnames. ora, you cannot create a tns alias for the adb database. Therefore, you can only use a full-write parsing symbol when creating the dblink. The method for creating a dblink is as follows:
Create database linkconnect to bdb identified by bdb
Using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = dbtestb)
)
)';
After creating a tns alias, you can use sqlplus username/password @ tnsname to test whether the created tns alias is correct.
A dblink example created in the production system:
Create database link NEW_DBLINK
Connect to AIIPS identified by "1qaz2wsx"
Using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.193.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = zjpub)
)
)';