1

We're using a thin driver to connect to Oracle:

jdbc:oracle:thin:@(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=22222)))(CONNECT_DATA=(SERVICE_NAME=servicename)))

This is just an example, the real connection string is much longer. It changes from time to time, so we have to update it in our configuration file each time.

Does Oracle have some kind of abstraction for the connection string (e.g., shortcut url), so we don't have to update the connection string when DBA changes something on the Oracle side? I strongly feel that an application should store only host name and port.

Kertis van Kertis
  • 711
  • 1
  • 9
  • 24
  • 2
    This might help: https://stackoverflow.com/questions/14194750/java-jdbc-how-to-connect-to-oracle-using-tnsnames-ora and https://stackoverflow.com/questions/19536162/how-to-connect-jdbc-to-tns-oracle – Mark Rotteveel Oct 25 '17 at 15:44
  • Thanks, but this requires access to tnsnames.ora. My question is more about changes that can be made on the Oracle side. – Kertis van Kertis Oct 25 '17 at 15:48
  • there are dozens of ways how to source connection details. From enterprise ones like jndi to much simpler property files (e.g. in Spring). Also you can source this from environment (encrypt credentials!). And btw your connection string seems weird. – Admit Oct 25 '17 at 15:51
  • My Oracle knowledge is a bit lacking in this area, but I think this would be more on-topic on https://dba.stackexchange.com/, maybe this gives an idea https://dba.stackexchange.com/questions/11873/how-does-name-resolution-work-in-oracle-10g – Mark Rotteveel Oct 25 '17 at 15:53
  • You can use a much simpler EZCONNECT syntax: jdbc:oracle:thin:@hostname:port/servicename – Cyrille MODIANO Oct 25 '17 at 15:56
  • If your Java code is running on a web server, then JNDI would be the "abstraction" layer you are looking for. Otherwise, you might look into Oracle Internet Directory to provide a centralized translation between the distinguished name for the server and it's connect string. And it works with JDBC thin drivers. See: https://docs.oracle.com/database/121/NETAG/config_concepts.htm#NETAG189. – Matthew McPeak Oct 25 '17 at 17:53

0 Answers0