创建连接时执行sql语句
为了使我们的应用程序正常工作,我们需要在每个新连接上执行 SQL 语句,然后再将该连接分发给应用程序。
如何在 WAS 7 中相应配置数据源?
我们找到了(已弃用的)选项来使用 sql 语句验证数据源,这有望达到目的(同事正在测试它)。这听起来是错误的,因为我们不是“测试”连接,而是正确设置它。而且它已被弃用,因此这可能会停止与 websphere 的未来版本一起使用
是否有一个干净且正确的方法来执行此操作?
我们想要执行的语句是
ALTER SESSION NLS_SORT='GERMAN_AI'
一种替代方法:应用程序是基于 hibernate 的,因此如果我们可以说服 hibernate 在使用连接之前执行该语句,那么这也可以工作。
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.
How do I configure a data source in WAS 7 accordingly?
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?
The statement we'd like to execute is
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果是我,我只会使用“连接测试”方法:
唯一的缺点是它会每次测试连接时都会执行,这在连接的生命周期中可能会执行很多次,但那又怎样 - 这是一个非常快的执行语句并且是幂等的,所以没问题。
If it were me, I would just use the "connection test" approach:
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.
无论如何,您不是 WAS 专家,但如果您可以设置 Tomcat JDBC 来提供数据库连接池,那么它有一个名为“initSQL”的参数。您可以将其设置为希望连接池在创建连接时运行的 SQL 语句。
Tomcat JDBC 连接池
Not a WAS expert by any means, but if you can set up Tomcat JDBC to provide your database connection pooling, it has a parameter amongst others called "initSQL". You can set that to a SQL statement that you want the connection pool to run whenever a connection is created.
Tomcat JDBC Connection Pool
A.
一种方法是使用自定义的 Hibernate 方言,因为您实际上指定了一种与数据库对话的“不同”方式。我不知道在哪里添加初始化代码。
One way to go would be to use a custom Hibernate dialect, since you are actually specifying a 'different' way to talk with the database. I have no idea where to add the initialization code though.