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

前端 未结 5 1381
深忆病人
深忆病人 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 09:38

    java.util.Properties props = new java.util.Properties();
    props.setProperty("password","mypassword");
    props.setProperty("user","myusername");
    props.put("v$session.osuser", System.getProperty("user.name").toString());
    props.put("v$session.machine", InetAddress.getLocalHost().getCanonicalHostName());
    props.put("v$session.program", "My Program Name");
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    Connection conn=
        DriverManager.getConnection("jdbc:oracle:thin:@myhostname:1521:mysid", props);
    

    SQL>select username,osuser,program,machine
    from v$session
    where username = 'ROB'; 
    
    USERNAME  OSUSER       PROGRAM             MACHINE
    --------- -----------  ------------------  -----------
    ROB       rmerkw       My Program Name     machine
    

    At application level you can use the following methods to set client_info, module and action in v$session:

    dbms_application_info.set_client_info
    dbms_application_info.set_module
    dbms_application_info.set_action
    

提交回复
热议问题