1

I am aware how to configure db connection using jdbc string

#Basic Spring Boot Config for Oracle
spring:
  datasource:
    url: jdbc:oracle:thin:@host:port:sid
    username: user
    password: pwd
    driver-class-name: oracle.jdbc.OracleDriver
    continueOnError: true

How do i do the same if i should be using tnsnames.ora file ?

deepakrm
  • 13
  • 1
  • 4

2 Answers2

1

Make sure you have a TNS alias in the connection string and as long as you set TNS_ADMIN to the place where tnsnames.ora file is present, you are set.

Note that passing TNS_ADMIN as part of the URL requires 18.3 JDBC drivers.

jdbc:oracle:thin:@wallet_dbname?TNS_ADMIN=$ORACLE_HOME/network/admin

tnsnames.ora

testdb = (description= (address=(protocol=tcps)(port=1521)(host=myorclhost))(connect_data=(service_name=myorclservice)))

Nirmala
  • 1,278
  • 1
  • 10
  • 11
0

First, determine which directory your TNSNAMES.ora file lives in. It is usually stored at $ORACLE_HOME/network/admin, but this may vary depending on how your client was installed.

Once you have the location of your TNSNAMES.ora file, you should set a property called oracle.net.tns_admin to point to that directory. Once the property is set, you specify the database you are trying to connect to.

Here are a couple of great examples that cover this method:

Connection to Oracle via TNS is not working

How to connect JDBC to tns oracle

1991DBA
  • 805
  • 1
  • 9
  • 18