通过JDBC连接时,在会话信息中显示应用程序名称 [英] Display application name in Session Information when connecting via JDBC
问题描述
我使用stardard JDBC驱动程序创建了与postgres 9数据库的连接。
I create a connection to a postgres 9 database using the stardard JDBC driver.
...
Connection myCon = DriverManager.getConnection("jdbc:postgresql://localhost/test?&user=test&password=test");
...
当我用PgAdmin检查服务器状态并显示所有数据库会话时,我可以看到没有为我的Session设置应用程序名称。有没有办法在JDBC连接中设置应用程序名称?
When I check the server status with PgAdmin and display all database sessions, I can see that the "Application Name" is not set for my Session. Is there a way to set the application name in the JDBC connection?
推荐答案
可以将应用程序名称设置为连接参数Postgres JDBC 9.1dev-900 :
That is possible to set application name as connection parameter since Postgres JDBC 9.1dev-900:
添加对连接启动
以及稍后通过Connection.setClientInfo设置application_name的支持。 (jurka)
Add support for setting application_name on both connection startup and later through Connection.setClientInfo. (jurka)
ex: jdbc:postgresql:// localhost:5432 / DbName?ApplicationName = MyApp
或 Connection.setClientInfo(ApplicationName,我的应用程序)
对于以前的版本,您可以通过设置 application_name
运行时参数来执行此操作:
For previous versions you could do this by setting application_name
runtime parameter:
s.execute("SET application_name TO 'MyApp'");
这篇关于通过JDBC连接时,在会话信息中显示应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!