The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Find it yourself, please...

Posted by Kishori Sharan on December 16, 2000 at 12:32 AM

I can just give you clue so that you can find the actual class name which implements all the methods of Connection interface in java.sql package in your case. When you get the connection
Connection con =DriverManager.getConnection ( "jdbc:oracle:thin:@dlsun511:1721:dbms733",
"scott", "tiger");
then you can get the name of the class of the real object con using con.getClass ( ) . You can also get the interfaces which the actual class of con at run time implements. I don't Oracle on my PC, but I did it for jdbcd-odbc driver and the actual class of con at run time is
class sun.jdbc.odbc.JdbcOdbcConnection implements sun.jdbc.odbc.JdbcOdbcConnectionInterface
If you start querying sun.jdbc.odbc.JdbcOdbcConnectionInterface and so on then you will get to know the exact class which in your particular case implements the methods defined in Connection interface.
In Test.java just change the driver and url to yours and run it to know the class hierarchy.
Thanx
Kishori

//////////// Test.java
import java.sql.* ;

public class Test {
public static void main ( String[] args ) {
Connection con = null ;
String driver = "sun.jdbc.odbc.JdbcOdbcDriver" ;
String url = "Jdbc:Odbc:PSDBASTS" ;
try {
// Load the driver
Class.forName ( driver ) ;

//Get the connection
con = DriverManager.getConnection ( url ) ;

// Get the class of the actual object in connection
Class c = con.getClass ( ) ;
printClassDeclaration ( c ) ;
c = c.getSuperclass ( ) ;

while ( c != Object.class ) {
printClassDeclaration ( c ) ;
c = c.getSuperclass ( ) ;
}

}
catch ( Exception e ) {
System.out.println ( e.getMessage ( ) ) ;
}
}

public static void printClassDeclaration ( Class c ) {
Class ii[] = c.getInterfaces ( );
String intf = "" ;

for ( int i = 0 ; i < ii.length ; i++ ) {
if ( i > 0 ) {
intf = intf + ", " + ii[i].getName ( ) ;
}
else {
intf = ii[i].getName ( ) ;
}
}

if ( intf.length ( ) > 0 ) {
System.out.println ( "class " + c.getName ( ) + " implements " + intf ) ;
}
else {
System.out.println ( "class " + c.getName ( ) ) ;
}


}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us