[英]Can we run initial sql in oracle jdbc connection on jetty?
I have a local jetty java project.我有一个本地码头 java 项目。 I would like to run some sql when the server creates any connections.当服务器创建任何连接时,我想运行一些 sql 。 The connections are configured in a jetty-env.xml file.连接在 jetty-env.xml 文件中配置。 Im hoping there is some oracle jdbc property like "run-sql-on-connect" where I can trigger the sql.我希望有一些 oracle jdbc 属性,例如“run-sql-on-connect”,我可以在其中触发 sql。 Essentially I want to alter the session whenever a connection is established.本质上,我想在建立连接时更改 session 。 Is there anything in OracleDataSource.connectionProperties like this? OracleDataSource.connectionProperties 中有这样的东西吗?
<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>
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参考: https://www.eclipse.org/jetty/javadoc/jetty-11/org/eclipse/jetty/webapp/WebAppContext.ZFC35FDC70D5FC69D269EZ883A822C7A53
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.