2

I have datasource configuration file where i have context with resource(s) like this

<Context>
     <Resource
        name="jdbc/pds"
        auth="Container"
        driverClassName="oracle.jdbc.driver.OracleDriver"
        factory="myPackage.EncryptedDataSourceFactory"
        logAbandoned="true"
        maxTotal="30"
        maxIdle="10"
        maxWaitMillis="1000"
        password="encryptedPassword"
        removeAbandoned="true"
        removeAbandonedTimeout="60"
        type="javax.sql.DataSource"
        url="jdbc:oracle:thin:@myFirstIP:port:MYDB"
        username="username"
        accessToUnderlyingConnectionAllowed="true"
    validationQuery="select 1 from dual" />
</Context>

My goal is to take data from base with the ip myFirstIP but if can not execute validationQuery with some reason , for example base is disabled, I want to take connect and take data from base with ip mySecondIP. I know that i can create second resource which has mySecondIP ip and check it on application side (in JAVA for me) if myFirstIP is disabled create connection with mySecondIP. But if I don't want additional checks on application side , can i make it using this configuration file to make default connection with myFirstIP and if it is disabled with mySecondIP?Is it possible ? If it is not possible what is best solution for my problem ?

I am using oracle 11.2.0.2.0 , java8 and tomcat 8.5 / wildfly 9

Gog1nA
  • 376
  • 1
  • 8
  • 30
  • Take a look at this [using-dynamic-datasource-with-tomcat](https://stackoverflow.com/questions/6055357/using-dynamic-datasource-with-tomcat) ...it seems similar. – PKey Feb 15 '18 at 09:04

1 Answers1

1

Using TNS keyword-value syntax with 2 or more address

 url="jdbc:oracle:thin:@(DESCRIPTION=(FAILOVER=ON)(LOAD_BALANCE=off)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.10.88)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.89)(PORT = 1521)))(CONNECT_DATA=(SERVICE_NAME = D88)(FAILOVER_MODE=(TYPE=select)(METHOD=basic))(SERVER = DEDICATED)))";
Dmitry Demin
  • 2,006
  • 2
  • 15
  • 18
  • where can i enter db_name here ? – Gog1nA Feb 15 '18 at 09:56
  • if you know service_name then `(SERVICE_NAME = D88)` or if ORACLE_SID then `(SID = D88)` – Dmitry Demin Feb 15 '18 at 10:02
  • syntax is like this i just need to change HOST and SERVICE_NAME values and first Address will be default active ya ? – Gog1nA Feb 15 '18 at 10:14
  • @Gog1nA You need to change the `HOST` and the `SERVICE_NAME`. The first address is used by default for the connection, if the first address does not have the required database `SERVICE_NAME` or the first address is not active, then try to connect to the second address. – Dmitry Demin Feb 15 '18 at 10:28