× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: JAVA/JDBC newbie question
  • From: "Richard Dettinger" <cujo@xxxxxxxxxx>
  • Date: Tue, 21 Nov 2000 09:30:35 -0600
  • Importance: Normal


Class is a class found in the java.lang package.  forName loads a class
into the Java virtual machine.  Therefore Class.forName goes out and finds
a specific class and loads it into the running JVM.

JDBC has the concept of the DriverManager which you request database
connections from.  JDBC drivers register themselves with the DriverManager
so that it knows about them and can use them to create database
connections.

JDBC drivers are supposed to have a static initializer which takes care of
registering themselves with the driver manager.  A static initializer is a
block of code that is only executed once and that happens when the class is
loaded but before any instances of the class are created.

Putting it all together:  You issue the Class.forName() call.  The JVM
loads the class that you specifiy (which is an implementation of the
java.sql.Driver interface).  When this class loads, the static initializer
in the class runs.  That static initializer registers the JDBC driver that
the class is for (the Native JDBC driver in this case).  Once this is done,
you can get JDBC connections with the driver through the driver manager.

Its a thing of beauty, isn't it?  :-)

One more thing:  the package in AS/400-land (make that iSeries-land) should
be "com.ibm.db2.jdbc.app.DB2Driver", not "COM.ibm.db2.jdbc.app.DB2Driver".
The uppercase "COM" is the package name on NT and other platforms whereas
the lowercase "com" is the AS/400 Native JDBC driver.  The short history of
that is that Sun waffled on how things should be done.  IBM went in two
different directions based on this information at different times and now
neither group can really change things or they will break customer
applications (for the record, our lowercase 'com' is the 'right' value).

Hope this info helps.

Regards,

Richard D. Dettinger
AS/400 Java Data Access Team

"TRUE! nervous, very, very dreadfully nervous I had been and am; but why
WILL you say that I am mad?
The disease had sharpened my senses, not destroyed, not dulled them. "

- Edgar Allan Poe
"The Tell-Tale Heart"




"Tom Tufankjian" <Tom_Tufankjian@hbltd.com>@midrange.com on 11/21/2000
08:47:01 AM

Please respond to JAVA400-L@midrange.com

Sent by:  owner-java400-l@midrange.com


To:   JAVA400-L@midrange.com
cc:
Subject:  JAVA/JDBC newbie question






I have seen the following code and would like to know what it does:

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

The documentation says it "enables Java to find the driver classes for
handling JDBC objects."

Specifically, what does the "Class.forName"  do?

Thanks for your help.

tom t


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.