Connecting to Oracle Using a TNS File with the JDBC Thin Driver

Connecting to Oracle via a TNS file with the JDBC thin driver requires the following information:

1. The location of the TNS file on the user's local machine
2. A service name that is configured in the TNS file.

If using RazorSQL to make the connection, select "TNS" as the connection type when creating a new Oracle connection. RazorSQL will look for the Oracle client installation on the user's machine and try to find the TNS file underneath the Oracle client installation. If RazorSQL finds the file, it will also populate the service names contained in the file in the "TNS Name" drop-down. If RazorSQL does not find the file, click the "Browse" button next to the "TNS File" field and point it to the location of the TNS file.

If creating a connection manually using a TNS file and the JDBC thin driver, a system property needs set to tell the Oracle JDBC thin driver the parent directory of the TNS file. The system property is the following:

The above system property needs set prior to making the connection attempt to Oracle. Below is an example of setting the system property in Java code:

System.setProperty("", "C:/oracle/product/11.2.0/client_1/NETWORK/ADMIN");

Once the system property has been set, the JDBC URL for the Oracle connection can be configured as follows.

jdbc:oracle:thin:@<Service Name from TNS File>

Here is an example URL when using the service name SAMPLE: