• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we are using jdbc program we are using Class.forName("sun.jdbc.odbc.JDbcOdbcDriver");
What is the meaning of the statement?
Then we are using Connection,ResultSet,Statement interfaces,where they have been implemented?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Vendor implements all the interfaces i.e. Driver,Statement etc. For Oracle take a look at classes.zip.

Loading a class means a new Driver(for the first time) is created and gets registered with Driver manager. When you use the DriverManager.getConnection() it locates the appropriate driver from the available registered driver and creates the connection.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chellam selvi:
When we are using jdbc program we are using Class.forName("sun.jdbc.odbc.JDbcOdbcDriver");
What is the meaning of the statement?
Then we are using Connection,ResultSet,Statement interfaces,where they have been implemented?



That loads the specified class into the JVM; that class (and all other JDBC-conformant drivers) in turn has a static initialization block that will register the driver with the DriverManager, thereyby making it available for use.

That driver is generally not a "production-capable" driver; database vendors have their own versions of a JDBC driver, some of which have ODBC capability. However, there are a few cases where sun.jdbc.odbc.JDbcOdbcDriver is the only free driver available for that type of data store; there are usually better but non-free drivers in those situations. Also however, in general, you should avoid using JDBC-ODBC bridges if you can, although there are times that you cannot.
 
selvi parthu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what is the return type for Class.forName(" ") method?
can we use Class.forName("java.lang.String");?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chellam selvi:
Then what is the return type for Class.forName(" ") method?
can we use Class.forName("java.lang.String");?



The return type is "Class" object. The main purpose of doing a Class.forname in JDBC is to execute the static initializer block which creates a new instance of the Driver and registers with the DriverManager.

The alternate way DriverManager.registerDriver(new Driver()); This means you dont have to load the class.
 
selvi parthu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, but registerDriver(new Driver()) is not recommended since it may result in the Driver class being registered twice, once by the driver when it loads, and again explicitly by you. Class.forName() works just fine.

Other ways to load drivers is to use the -Djdbc.driver=com.driver.Driver or to use a DataSource.

Of them all, the DataSource is preferred then Class.forName(). I've never seen the -D option used commonly but it works too, people generally prefer to put Driver settings in a properties file rather than using -D
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

True, but registerDriver(new Driver()) is not recommended since it may result in the Driver class being registered twice, once by the driver when it loads, and again explicitly by you. Class.forName() works just fine.



It actually registers it two times atleast in Sun JDK.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic