Can we run initial sql in oracle jdbc connection on jetty?

Viewed 17

I have a local jetty java project. I would like to run some sql when the server creates any connections. The connections are configured in a jetty-env.xml file. Im hoping there is some oracle jdbc property like "run-sql-on-connect" where I can trigger the sql. Essentially I want to alter the session whenever a connection is established. Is there anything in OracleDataSource.connectionProperties like this?

<New id="OracleDS_local" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jdbc/local</Arg>
    <Arg>
        <New class="oracle.jdbc.pool.OracleDataSource">
            <Set name="URL">jdbc:oracle:thin:*******</Set>
            <Set name="user">*****</Set>
            <Set name="password">****</Set>
            <Set name="connectionProperties ">
                <Set name="run-sql-on-connect" >alter session sql here</Set>
            </Set>
        </New>
    </Arg>
</New>
1 Answers

A possible workaround/solution (depending on the requirements) would be to use a custom context handler and a related event to perform a separate connection and execute the query you want.

I know it's not an optimal solution but it might do the trick.

Reference: https://www.eclipse.org/jetty/javadoc/jetty-11/org/eclipse/jetty/webapp/WebAppContext.html

<Configure id='oracledbdemo' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="OracleDS_local" class="org.mortbay.jetty.plus.naming.Resource">
...
</Configure>

REPLACE WITH

<Configure id='oracledbdemo' class="<YOUR_CUSTOM_WebAppContext_HERE">
</Configure>
Related