Why Connection is declared as an interface?

Why the data access members in the java.sql packages are defined as interfaces e.g Connection, Statement, ResultSet? Why not they had been defined as Class itself? What is the internal mechanism of getting the Connection objects when calling the getConnection() method of DriverManager class?

I have some more doubts to be clarified. Once u have loaded the Driver
class using Class.forName() method, who is registering
the driver class with the DriverManager.Each driver implementaion class (for example OracleDriver, JdbcOdbcDriver) will have a static block, inside which they will execute the statement
DriverManager.registerDriver(new driver_class()); This statement registers the driver with DriverManager. You can register as many drivers as you can.
When the DriverManager class is instantiated/loaded in the JRE?
where are the implemented classes like JdbcOdbcConnection available?
b'coz we r only instantiating the JdbcOdbcDriver class.Now the DriverManager takes the overall burden of giving connection to you. It will dicide the connection based on the connection url you will pass to it. If you pass the con url "jdbc:oracle:thin:@server:1521:sid". Then DriverManager will establish the connection with that server and at that port for that sid and gives you OracleConnection object. Your OracleConnection will create OracleStatement for you and this OracleStatement can create OracleResultSet for you.
You can find these classes in classes12.zip, JdbcOdbc classes in rt.jar.
You can find rt.jar in jdk_installation\jre\lib dir. This jar file will be automatically included in the classpath and thats the reason why you are not aware of it. Whereas for Oracle, you need to explicitly include OracleDriver (classes12.zip or classes101.zip) into the classpath.
Plaese don't ask me how to see the source code of those classes. I can't tell you to decompile them because it is against the license agreement.
Hope this helps.
Sudha

Similar Messages

  • Why the HashMap implements the Map interface twice

    See the type hierarchy below:
    HashMap<K,V>
    &#9475;
    &#9507;AbstractMap<K,V>
    &#9475;&#9475;
    &#9475;&#9495;Map<K,V>
    &#9495;Map<K,V>
    The HashMap extends AbstractMap, which implements Map. So the HashMap has already implements Map, and has the Map type. But the HashMap's declaration still contains "implements Map".
    So why the HashMap implements the Map interface twice?
    Thanks in advance.

    georgemc wrote:
    Maybe the guy who wrote HashMap wanted to make it clear that HashMap implemented Map, rather than rely on you looking further up the hierarchy to find outYes, it does make the Javadoc clearer. If they hadn't done that then there would have been legions of newbies who couldn't tell that HashMap implemented Map and thousands of "I have a doubt, does HashMap implement Map" questions here.

  • Why do we declare the variables private in a bean

    Hi,
    when we create a bean in the MVC architecture why do we declare the variables private. Also when do we use the access specifier private.
    Regards,
    Prashant

    pksingh79 wrote:
    Hi ^^,
    thanks for replying.I had a discussion with one of my trainers and he was of the opinion that the variables should generally be declared private. In this way we prevent classes from accessing and setting illegal values to those variables.
    Say for instance we have the class person as follows:
    public class Person
    int age;
    setAge(int age)
    if (age < 0)
    return null
    Person p = new Person() ;
    p.age = -2;
    //this would be perfectly legal
    //where as if we declare the variable as private as follows:
    public class Person
    private int age;
    setAge(int age)
    if (age < 0)
    return null
    Person p = new Person() ;
    // P.age = -2;   this would be illegal as age is private and would have to be accessed by the method defined above.
    p.setAge(-2);
    //the cbove line would retun null values.
    public class Person {
        private int age;
        public void setAge(int age) {
            if (age < 0) {
                throw new IllegalArgumentException("...");
            this.age = age;
    }

  • Why do we configure the Redundant Interface in CSS Public Face

    Hi,
    I have a question : Why do we configure the redundant interface in a CSS facing the public side of a CSS.
    I understand the need for the interface in the server side though. Please refer to the URL below;
    http://www.cisco.com/univercd/cc/td/doc/product/webscale/css/css_810/redundgd/vipredun.htm#wp1063393

    this is not a requirement if your vips belong to the public vlan subnet.
    But if your vip addresses are from a different subnet, then the upstream router needs a route pointing to the CSS redundant interface ip.
    Gilles.

  • Why I should declare a final object!

    import java.util.*;
    public class Problem {
    public static void main(String[] args) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
    public void run() {
    System.out.println("Exiting.");
    timer.cancel();
    5000);
    System.out.println("In 5 seconds this
    application will exit. ");
    When I complie the program there is one error as follow:
    Problem.java:11: local variable timer is accessed from within inner class; needs
    to be declared final
    timer.cancel();
    1 error
    I don't kown why I must declare the timer as "final"!
    Help me!

    What you have is an anonymous inner class. For this class to be able to access local variables in the containing class they must be final. When the compiler compiles the code it will create the inner class with a reference to the variable. If you were able to change the variable the inner class would lose the reference.

  • Use VPN connection as a listen network interface in Web Application proxy

    I have a test environment: domain in hyper-v with Sharepoint and Office Web Apps servers (all under Windows 2012 - Windows 2012 R2).
    Because my home ISP does not permit some inbound ports (80,443) in a gate machine (under Windows 2012 R2) I create a vpn connection (by "setup a new connection or network") to my outside vpn server. On this vpn server the ports forwarding is configured
    and work fine (f.e. default IIS site is visible).
    I try to public my Sharepoint 2013 Foundation in Internet over this vpn connection and faced with the problem - WAPx (Web application proxy) does not bind to this vpn connection, only to traditional network interfaces.
    The question is how to make listening WAPx the VPN interface?

    Hi,
    Thank you for posting in Windows Server Forum.
    Please check beneath thread and article might helpful in your case.
    Configure a reverse proxy device for SharePoint Server 2013 hybrid
    http://technet.microsoft.com/en-us/library/dn607304(v=office.15).aspx
    Forcing VPN users through a proxy
    http://social.technet.microsoft.com/Forums/en-US/5a6a502d-4583-4c51-8486-3af982ba92da/forcing-vpn-users-through-a-proxy?forum=winserverNIS
    What’s New in 2012 R2: People-centric IT in Action - End-to-end Scenarios Across Products
    http://blogs.technet.com/b/in_the_cloud/archive/2013/07/17/people-centric-it-in-action-end-to-end-scenarios-across-products.aspx
    Hope it helps!
    Thanks,
    Dharmesh

  • Why the ArrayList implements the List interface

    Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?

    899440 wrote:
    Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?I dont think there's any specific reason for that. In my opinion its redundant. May be its added for clarity so that from the documentation its obivous that ArrayList implements List.
    May be there's something which I am missing regarding this?

  • Connection between CRS 1 POS interfaces and 7600 POS Interfaces

    Hi,
    I am trying to connect a CRS 1 POS interface to a Cisco 7609 POS interface and i keep geting the following alarms, and the line protocol i s down on both device ends
    RP/0/RP0/CPU0:at_crs_01#LC/0/2/CPU0:May 1 10:42:47.363 GMT0: spa_oc48[245]: %L2-SONET_LOCAL-4-ALARM : SONET0/2/0/2: SLOS cleared.
    Please help!!
    Attached are the configurations on the Devices

    Hello Obiora,
    if the two are connected in back to back: one side provide the clock with
    clock source internal
    the other side should take the clock from line
    clock source line
    I would change one of the two in clock source line
    Hope to help
    Giuseppe

  • Why we require to implement Serializable interface?

    Hi techies,
    I am new to Serialization. Why we require to use Serializable interface for Serializing objects. Since Serializable interface is a marker interface, how it prevents objects not implementing Serializable from being Serialized. Does Java Compiler checks it or how it checks it?

    JavaBreather wrote:
    Since Serializable interface is a marker interface, how it prevents objects not implementing Serializable from being >Serialized. Does Java Compiler checks it or how it checks it?Compiler does nothing but mark the class as implementing the interface. You can then later check whether “objects instanceof Interface" and find out whether or not it is present. As said above, ObjectOutputStream does the same thing.
    Marker interfaces are a misuse of interfaces, and should be avoided. You shouldn't create new ones.Annotations introduce in Java 5 are a generic mechanism of adding metadata to a class.

  • Why do we need empty serializable interface??

    I see almost all classes implementing serializable. Why cant we have this interace declared at the Object level itself??
    abstract class Object implements Serialiazable{
    Is there any reason for not having at the object level itself.???
    And
    Why they have not put method compareTo(Object o) inside Comparable interface???

    Is there any reason for not having at the object level itself.???1. Not all objects are serializable.
    Eg:Thread, OutputStream and its subclasses, and Socket are not serializable.
    2. Serializable should be implemented judiciously.
    Extracted from Effective Java: Programming Language Guide
    Allowing a class's instances to be serialized can be as simple as adding the words
    �implements Serializable� to its declaration. Because this is so easy to do, there is
    a common misconception that serialization requires little effort on the part of the programmer.
    The truth is far more complex. While the immediate cost to make a class serializable can be
    negligible, the long-term costs are often substantial.There are numerous reasons. Please refer to the book.
    >
    And
    Why they have not put method compareTo(Object o) inside Comparable interface???[http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html#compareTo(T)]

  • Method declaration of an interface

    Hi,
    Here's an interface definition.
    public interface Foo {
    public Object getSomeObject(Object param);
    What i want to find out is,
    why do we need to specify a variable reference in the interface?
    public interface Foo {
    public Object getSomeObject(Object);//throws error.
    Thank you.

    Hi,
    Here's an interface definition.
    public interface Foo {
    public Object getSomeObject(Object param);
    What i want to find out is,
    why do we need to specify a variable reference inthe
    interface?
    public interface Foo {
    public Object getSomeObject(Object);//throwserror.
    Thank you.The interface method is just a signature that all
    classes implementing the interface must follow. Its
    syntax requires that the variable reference is
    included. There is no other reason. Its like the word
    "bought" is spelt the way it is..It could have also
    been splet as "bot" but that is incorrect.!!!
    That is right.
    It is just a signature. Also, it allows the compiler to perform its actions consistently, most of all, thereby not offering any special privileges to an interface method declaration. As we all know that the byte code representation of an 'interface type' is also a class.

  • Question about declaring type as interface

    Hi
    I am trying to get my head around declaring an object as the interface type (I think this is right correct me if I am wrong). Ok so I understand if I declare my object reference as the interface I will only get the methods of the interface defined in the objects class..? ie
    List myList = new ArrayList();I think any method particular to ArrayList will not be there. But I dont actually understand wha is happening here, I have a ref to a List but the object is actually an ArrayList?
    So if I passed ths list to a session object and got it out I could cast it back to the interface. I dont understand why or what is happening here.
    I hope someone understands my question enough that they can help me out, this has been nugging me for a while.
    Thanks

    I am trying to get my head around declaring an object
    as the interface type (I think this is right correct
    me if I am wrong). Ok so I understand if I declare my
    object reference as the interface I will only get the
    methods of the interface defined in the objects
    class..? ie
    List myList = new ArrayList();I think any method particular to ArrayList will not
    be there. If you use myList without casting, then, yes, only List's methods will be available, because all the compiler knows is that it's a reference to a List. It doesn't know that at runtime it will point to an ArrayList object.
    You could cast myList to ArrayList to get ArrayList-specific things (if there are any), but a) if you're not careful, you can end up with a ClassCastException at runtime (you won't here, but in general you can) and b) if you're going to do that, you have to question why you declared it as a List in the first place. There are cases where casting is appropriate, but you have to be careful.
    But I dont actually understand wha is
    happening here, I have a ref to a List but the object
    is actually an ArrayList?Yes.
    So if I passed ths list to a session object and got
    it out I could cast it back to the interface. I dont
    understand why or what is happening here.You could cast it to anything that the object actually is, that is, any of its superclasses and superinterfaces. If it's an ArrayList, you could cast it to any of the following: ArrayList, AbstractList, AbstractCollection, Object, Serializable, Cloneable, Iterable, Collection, List, RandomAccess.

  • Unity Connection 7.1.3 user interface webpage access problem

       I'm running Cisco Unity Connection 7.1.3.10000-68 on a vmware 1.0.8 platform in lab and I'm trying to access the user interface
    "http//:<UnityPublisher Address>/ciscopca" and I get the web error message:
    HTTP Status 404 - /ciscopca
    type: Status report
    message: /ciscopca
    description: The requested resource (/ciscopca) is not available.
       I've checked that all the sevices are activated and I can't figure out why the user interface isn't working. Am I missing something or does Unity Connection on a VMWare platform not support access to the user interface webpage?
    Thanks,
    Jim

    David,
          I had it at 1024 and I bumped it up to 2048 and now it works.
    Thank you very much!
    Jim

  • Can't connect to router's admin interface (WRT54G v3.1)

    Hi.
    I have problem with my Linksys WRT54G v3.1 router. I can't connect to its admin interface and broadband Internet connection doesn't work.
    The power LED is flashing. When I restart the router or unplug and plug it again, nothing happens. The power LED just continue to flash and I can't connect to the router. I even tried to put new firmware but program that I downloaded from linksys.com can't connect to the router.
    When I enter http://192.168.1.1 into Firefox or Explorer, I get "Connecting to http://192.168.1.1..." and nothing else happens.
    I hope that someone can help me because it's pretty annoying that my home network doesn't work...
    Thank in advance, Sasha.Message Edited by k31k0 on 12-26-200603:27 AM
    Message Edited by k31k0 on 12-26-200603:28 AM

    Sounds like your router is bricked, flashing power LED is not good.  Contact the RMA department and explain whats going on.  Your router has the Linux operating system.  When you talk to them make sure you mention this and you want the same router as a replacement which is the WRT54GL.  If you dont specify that you want the same they will send you a version 6.  Then you are looking at more headaches.
    In the RMA form you have to add "ONLY" to the version box on the RMA form. That's because most customers prefer the latest if they have it, and they try to accommodate as much as possible. Rarely is there a need for a specific version.
    Message Edited by wehowardjr on 12-26-200607:00 AM

  • Why BPM contains only ABSTRACT messgae interfaces

    Hi Forum,
    Can u please help me in finding why BPM can only support ABSTRACT Message Interfaces.....
    thanks
    Edited by: sudeep dhar on Jan 16, 2008 9:28 AM

    Sudeep,
    Refer to http://help.sap.com/saphelp_nw04/helpdata/en/4b/d26b3d32390968e10000000a114084/frameset.htm for a description of the Communication Parameters
    Alternatively, from the SDN SAP on DB2 for Linux, UNIX, and Windows you can pull up the SAP documentation for SAP XI 3.0 and enter the search term 'Abstract message'
    Hope this helps,
    Mike

Maybe you are looking for