日期:2014-05-16  浏览次数:20434 次

如何区别数据库访问的客户端
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);

query v$session
SQL>select username,osuser,program,machine
from v$session
where username = 'ROB';

USERNAME  OSUSER       PROGRAM             MACHINE
--------- -----------  ------------------  -----------
ROB       rmerkw       My Program Name     machine
--------------分割线-----------
如果使用C3P0
<property name="properties">
<props>
<prop key="user">xxx</prop>
<prop key="password">xxx</prop>
<prop key="v$session.program">xxx</prop>
<prop key="v$session.osuser">xxx</prop>
<prop key="v$session.machine">xxx</prop>
</props>
</property>