Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JDBC Drivers

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Location
    Mumbai
    Posts
    10
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default JDBC Drivers

    I have learned that there are four types of Driver which are JDBC ODBC Bridge , JDBC Native Api , JDBC-Net Pure Java and 100% pure Java.When I searched for there implementation I came across only one way of registering the driver i.e. using Class.forName().Is this the way to register all four type of Driver.


  2. #2
    Junior Member
    Join Date
    Sep 2014
    Location
    bangalore
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC Drivers

    Yes. We can register the drivers using Class.forName()
    There is one more way, which is long and creates tight coupling.
    1. Create an object of driver given by DB vendor and register that object with java.sql.DriverManager which is a class and a part of JDBC API.
    e.g
    Driver driver= new Driver();
    DriverManager.registerDriver(driver);
    Here, Driver is a class in com.mysql.jdbc.Driver

    2. Any driver class given by DB vendor must inherit java.sql.Driver interface (for obvious reasons).

    3. The DB vendor in the Driver class must write a static block and inside the static block the driver object should be created and registered with driver manager.
    e.g
    com.mysql.jdbc.Driver implements java.sql.Driver
    {
    {
    DriverManager.registerDriver(new Driver());
    }
    }

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JDBC Drivers

    When I searched for there implementation I came across only one way of registering the driver i.e. using Class.forName().Is this the way to register all four type of Driver.
    Suggested reading: Establishing a Connection (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JDBC Drivers

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    Thread moved.

  5. #5

    Default Re: JDBC Drivers

    1. JDBC-ODBC Bridge driver :

    The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.

    2. Native-API/partly Java driver :

    The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database.

    3. All Java/Net-protocol driver :

    Type 3 database requests are passed through the network to the middle-tier server. The middle-tier then translates the request to the database. If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.

    4. Native-protocol/all-Java driver:

    The Type 4 uses java networking libraries to communicate directly with the database server.
    Last edited by Norm; September 13th, 2017 at 05:18 AM. Reason: URL removed

Similar Threads

  1. JDBC drivers
    By abhishek333 in forum JDBC & Databases
    Replies: 2
    Last Post: August 4th, 2014, 11:36 AM
  2. JDBC drivers
    By abhishek333 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 3rd, 2014, 11:48 AM
  3. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  4. Missing drivers?
    By mjpam in forum JDBC & Databases
    Replies: 5
    Last Post: September 6th, 2010, 08:00 PM
  5. JDBC
    By Abdul Rasheed in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2010, 07:01 AM