Skip to Main Content
  • Questions
  • Setting user information from jdbc client

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Paul.

Asked: July 01, 2001 - 10:57 pm UTC

Last updated: March 25, 2004 - 9:19 pm UTC

Version: 8.1.5

Viewed 1000+ times

You Asked

Hi Tom,

if you run
select username,server,osuser,machine,terminal from v$session.
it displays:
username server osuser machine terminal
USER1 NONE jdbcuser jdbcclient unknown

My question is: Is there any way for a jdbc client application to set the values for server, machine and terminal?

Thank you!

Paul Huang

and Tom said...

Not really.

Point 1 -- they most likely don't have a terminal (middle tier I suspect or running on a platform like windoze that does not have the concept of a terminal).

Point 2 -- if you use the Oracle jdbc drivers, they do set the machine name properly, i've never seen them NOT set it.


Point 3 -- the OSUSER is the osuser running the dedicated or shared server, not the remote OS user.


Using DBMS_APPLICATION_INFO, you can set this information manually into v$session -- the client_info, action and module columns.



Followup to comment

I just tried it out:

$ cat Emp.java
import java.sql.*;

class Emp
{
public static void main(String[] args) throws SQLException
{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;

try
{
// Load Oracle driver
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
String connect_string =
"jdbc:oracle:oci8:@ora8i.us.oracle.com";

// Connect to the local database
conn = DriverManager.getConnection
(connect_string,"scott", "tiger");

// Query the employee names by job
ps = conn.prepareStatement
( "select username || ',' || server ||','|| osuser||','||machine||','||terminal " +
" from v$session " +
"where sid = ( select sid from v$mystat where rownum = 1 )" );

rs = ps.executeQuery();

while (rs.next())
System.out.println( rs.getString(1) );

rs.close();
ps.close();
conn.close();
}
catch (Exception e)
{
System.out.println(e + "\n");
}
finally
{
if ( rs != null ) rs.close();
if ( ps != null ) ps.close();
if ( conn != null ) conn.close();
}
}
}

$ javac Emp.java

$ java Emp
SCOTT,DEDICATED,tkyte,aria,pts/5


followup to comment

did you use the THICK or THIN drivers. I used OCI8.



Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

DBArtisan does it

Paul Huang, July 08, 2001 - 12:54 am UTC

I did use Oracle jdbc driver when I made the select.
If you use DBArtisan, you can see the columns for OSUSER, MACHINE, TERMINAL, PROGRAM and COMMAND are set when you bring up the monitor screen.

Does it run anywhere?

Paul Huang, July 09, 2001 - 10:51 am UTC

I ran the program on NT. Here is part of the output:

MIS,DEDICATED,jdbcuser,jdbcclient,unknown
MIS,DEDICATED,jdbcuser,jdbcclient,unknown
MIS,DEDICATED,jdbcuser,jdbcclient,unknown
MIS,DEDICATED,U028071,FINANCIAL_MIS\WK,WK1CMP22_ZHIMIH
MIS,DEDICATED,U028071,FINANCIAL_MIS\WK,WK1CMP22_ZHIMIH

The 2 lines with U028071 in ODUSER column are connections started by DBArtisan. The rest are jdbc client connections. Are there any configuration or platform requrements needed to get what you got?

Paul,

Version 8.1.6 and above only?

Paul Huang, July 09, 2001 - 12:29 pm UTC

If I connect to version 8.1.6, I see the info. What about version 8.1.5?

Paul,

Question on your 'Point 2'

A reader, April 03, 2002 - 10:21 am UTC

Tom, regarding your following comment...
###
Point 2 -- if you use the Oracle jdbc drivers, they do set the machine name
properly, i've never seen them NOT set it.
###

Do oracle thin driver also always set the machine name? I have come across some pesky 'jdbc client' type of connections (with oracle thin driver), where machine name is not filled in. What would it take for us to get the machine name with thin driver? Or would we have to use OCI8 instead? We use weblogic 5.1 and oracle 8.1.6 or 9i. What would be the advantages or disadvantages of switching from thin to OCI8.
Thanks.



Tom Kyte
April 03, 2002 - 10:28 am UTC

thin probably does not do it (easy to find out, take the application i have above and try it)

there are many advantages to OCI8, features not available with thin and speed being the two that pop into my head.

On an app server (you have 10's of these), I would definitely be using THICK oci drivers -- on a client workstation (you have 100's or 1000's of these) I would be using THIN.

Can JDBC thin client use share server on 9.0.1?

John, March 25, 2004 - 12:45 pm UTC

Hi Tom,

As I understand, client must use Oracle net to use share server. That means JDBC thin client cannot use share server, only dedicate? I checked SERVER column on the v$session table, and got NONE value. Can you please tell me what NONE means since I didn't find it in the Oracle document. Are there only two types conection(dedicated or shared) in the Oracle 9.0.1?

Thanks.

Tom Kyte
March 25, 2004 - 9:19 pm UTC

jdbc thin uses "net" (think about it -- thin clients are usually NOT on the server, they must be using net...)

if you got NONE, that is an idle shared server connection!

see also:
</code> http://docs.oracle.com/docs/cd/B10501_01/server.920/a96536/ch3171.htm#1122127 <code>