How do I make my Java application identify itself to Oracle on connection?

前端 未结 5 1376
深忆病人
深忆病人 2020-12-24 09:33

When my application connects to an Oracle database I want to be able to see by looking at the active sessions in the database that it is connected. Currently it identifies i

5条回答
  •  爱一瞬间的悲伤
    2020-12-24 10:01

    Starting with 12.1 the setEndToEndMetrics is deprecated, you may use setClientInfo see the documentation for 12.2 here

    Here a snippet of the usage

    // "conn" is an instance of java.sql.Connection:
    conn.setClientInfo("OCSID.CLIENTID", "clientID");
    conn.setClientInfo("OCSID.MODULE", "myModule");
    conn.setClientInfo("OCSID.ACTION", "myAction");
    

    You may see the setting in V$SESSION with this query of the relevant session

     select MODULE, ACTION, CLIENT_IDENTIFIER from v$session where ...
    

    but only after a next statement is executed with this connection. The call of setClientInfo triggers no extra roundtrip this information is passed whit the next call.

    Note also that you must use the Oracle (unwrapped) conenction - Check this for reference.

提交回复
热议问题