I am trying to connect to Oracle database using TNS.
The problem is that TNS alias contains dot, so when I am specifying url like this:
jdbc:oracle:thin:@TNS.ALIAS
I've got...
oracle.net.ns.NetException: Invalid connection string format, a valid format is: "host:port:sid"
...during creation of connection.
I know that dot character is a problem, because after removing it from tnsnames.ora
file connection to database works.
My question is - is it possible to escape dot character somehow? Maybe there is some connection parameter that can be setup to allow dot character in alias? I would like to avoid removing dot from tnsnames.ora
since i am getting the file from outside source.
Here are the options that I've already tried that gave me the same error:
jdbc:oracle:thin:@"TNS.ALIAS"
jdbc:oracle:thin:@\"TNS.ALIAS\"
jdbc:oracle:thin:@`TNS.ALIAS`
jdbc:oracle:thin:@TNS\.ALIAS - this one is not compiling
jdbc:oracle:thin:@TNS\\.ALIAS
jdbc:oracle:thin:@TNS.ALIAS
jdbc:oracle:thin:@TNS\".\"ALIAS
jdbc:oracle:thin:@TNS%2eALIAS
Here are the options that resulted with oracle.net.ns.NetException: could not resolve the connect identifier
:
jdbc:oracle:thin:@TNSALIAS
jdbc:oracle:thin:@TNS-ALIAS
jdbc:oracle:thin:@TNS_ALIAS
Additional context:
DataSource
(OracleDataSource
to be
strict) in Scala (it is Play Framework - but I am not using Play's
way of creation of DB connections - I am doing it manually)tnsnames.ora
file and it is working there tnsnames.ora
file and it is working there (data source is defined like this: <add name="connectionName" connectionString="Data Source=TNS.ALIAS;"/>
I've found the problem - I was using older Oracle driver (ojdbc7.jar
for version 12.1.0.1
) after change to newer one (ojdbc8.jar
for version 12.2.0.1
) lookup by TNS alias started to work - there was no need to escape anything