Results 1 to 12 of 12
  1. #1
    Riyaz.hk77 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Loading of JDBC Driver

    Hi Can i use OracleDriver od= new oracleDriver(...) to load the driver manager class in static way instead of dynamic way of class.forName(...), please suggest:confused::confused:

  2. #2
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    OracleDriver? What API are you using?
    Anyways, the only JDBC I knew for oracle is similar to MySQL.
    But instead of loading the MySQL library, you must load/import the oracle driver (*.jar files).

    And with the static way. I don't about that.
    Java Code:
    Class.forName(driverName).newInstance();
    This is the only way (In my terms, I haven't tried other ways yet).

    Cyril H.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Riyaz.hk77 View Post
    what are the different ways to load driver manager class while using jdbc, plzzzzzzzzzzzzzz explain:confused:
    It depends on the driver and its version. Old drivers had to be instantiated, e.g. new MyDriver(); and you had to register them at the DriverManager. Later on you just had to mention the class as in ClassForName("foo.bar.MyDriver") and the driver would load and register itself. Again a bit later the DriverManager took a more active role and would read the "jdbc.drivers" property for available drivers and preload them. Nowadays the DataSource is the big hype. Read all about it in its API documentation.

    kind regards,

    Jos

  4. #4
    Riyaz.hk77 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Loading of Driver class

    Thnx, i wantto import the oracle driver and load the driver class in a static way. how can i do that

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    OP, please knock off the multiposting. I've locked your other two threads and have moved JosAH's reply here.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Riyaz.hk77 View Post
    Thnx, i wantto import the oracle driver and load the driver class in a static way. how can i do that
    Instantiate a driver with the Class.forName( ... ) trick and get a connection by asking the DriverManager.getConnection( ... ) call.

    kind regards,

    Jos

  7. #7
    Riyaz.hk77 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default way to load JDBC driver

    Hi Jos thnx, but what u have suggested is dynamic way of loading the driver and it works fine but still i m not cleared on my question. Can i load a driver like for example Myclass m1= new Myclass();

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    You can use this to register the driver directly if you want:
    Java Code:
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    That's the other technique, if you don't plan on changing the database behind your code.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Riyaz.hk77 View Post
    Hi Jos thnx, but what u have suggested is dynamic way of loading the driver and it works fine but still i m not cleared on my question. Can i load a driver like for example Myclass m1= new Myclass();
    That depends on the Driver. Does it have a no args public constructor? Does it register itself in that constructor? You have to follow the way the driver wants to be instantiated; for all other methods you're on your own.

    kind regards,

    Jos

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    That depends on the Driver. Does it have a no args public constructor? Does it register itself in that constructor? You have to follow the way the driver wants to be instantiated; for all other methods you're on your own.

    kind regards,

    Jos
    The answer to that is, yes...it does have a no args constructor.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    The answer to that is, yes...it does have a no args constructor.
    Well, then all we can hope for is that the driver registers itself somewhere in its public constructor code, otherwise that would be a driver for in the fire place ;-)

    kind regards,

    Jos

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    Well, there are two recommended ways for registering it.
    The Class.forName() one and the above one I posted (registerDriver()).

    Which is no different to any other driver.
    WHy someone wants to do "Driver d = new OracleDriver();" I have absolutely no idea. You gain nothing at all from that.

Similar Threads

  1. com.mysql.jdbc.Driver
    By uthpalaw in forum Eclipse
    Replies: 2
    Last Post: 10-14-2010, 06:09 AM
  2. JDBC Driver
    By Ursula in forum New To Java
    Replies: 6
    Last Post: 08-23-2010, 06:41 PM
  3. DB2 JDBC Driver upgrade
    By sanssan in forum JDBC
    Replies: 2
    Last Post: 09-23-2008, 05:52 PM
  4. JDBC Driver problem
    By Swamipsn in forum New To Java
    Replies: 3
    Last Post: 08-09-2007, 04:55 PM
  5. Help with JDBC driver
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 07-03-2007, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •