创建连接时执行sql语句 [英] Execute a sql statement when a connection is created

查看:120
本文介绍了创建连接时执行sql语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了使我们的应用程序正常运行,我们需要在每个新连接上执行一个SQL语句,然后将该连接移交给应用程序。

For our application to work properly we need to execute a SQL Statement on every new connection, before that connection is handed out to the application.

我如何配置相应地,WAS 7中有一个数据源吗?

How do I configure a data source in WAS 7 accordingly?

我们发现了(不推荐使用)选项,可以使用sql语句验证数据源,希望可以做到这一点(同事正在对其进行正确测试)现在)。这听起来是错误的,因为我们不是在测试连接,而是正确地设置了连接。同样不推荐使用它,因此这可能会停止与将来版本的Websphere一起使用

We found the (deprecated) option to validate the datasource using a sql statement, which hopefully does the trick (coworker is testing it right now). This sounds wrong, since we are not 'testing' the connection, but setting it up properly. Also its deprecated so this probably will stop working with future versions of websphere

是否有一种干净正确的方法?

Is there a clean and correct way to do this?

我们要执行的语句是

ALTER SESSION NLS_SORT='GERMAN_AI'

另一种方法:应用程序基于休眠,因此如果我们可以说服休眠状态在使用连接之前执行该语句,

One alternative approache: The application is hibernate based, so if we could convince hibernate to execute the statement before using a connection, this would work as well.

推荐答案

如果是我,我只会使用连接测试方法:

If it were me, I would just use the "connection test" approach:


  • 有效!

  • YAGNI 原则说:担心折旧何时发生... 如果曾经发生过-可能要等好几年了,或者永远都不会

  • 您不会通过找到正确的方式来增加任何业务价值

  • 您可以删除它并继续进行一些 real 工作lly为您的项目增加价值

  • It works!
  • The YAGNI principle says "worry about deprecation when it happens... if it ever happens" - probably years away or never
  • You will not add any business value by finding the "correct" way
  • You can drop this and get on with some real work that actually adds value to your project

唯一的缺点是它将在每次连接时执行 经过测试,在连接的生命周期中可能会多次,但是那又如何-它是一条执行速度非常快的语句,并且是幂等的,所以没问题。

The only downside is that it will be executed every time a connection is tested, which may be many times during the life of the connection, but so what - it's a very fast executing statement and is idempotent, so no problem.

这篇关于创建连接时执行sql语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆