What should I put in class.forName(). [message #91056] |
Tue, 12 March 2002 07:13 |
Lawrence Luk
Messages: 1 Registered: March 2002
|
Junior Member |
|
|
I want to connect to the Oracle database 8i with JSP and Java Bean. But it won't work when I put Class.forName(oracle.jdbc.driver.OracleDriver). What do I need to put in for the Class.forName.
Thanks very much
|
|
|
|
Re: What should I put in class.forName(). [message #91318 is a reply to message #91056] |
Sat, 13 July 2002 01:34 |
aditya
Messages: 36 Registered: March 2001
|
Member |
|
|
Hi Yogita,
Basically JDBC provides a driver manager that dynamically maintains all the driver objects that your database queries will need. So if you have three different kinds of vendor databases to connect to, you’ll need three different driver objects. The driver objects register themselves with the driver manager at the time of loading, and you can force the loading using Class.forName( ).
To open a database, you must create a "database URL" that specifies:
1. That you’re using JDBC with "jdbc."
2. The "subprotocol": the name of the driver or the name of a database connectivity mechanism. Since the design of JDBC was inspired by ODBC, the first subprotocol available is the "jdbc-odbc bridge," specified by "odbc."
3. The database identifier. This varies with the database driver used, but it generally provides a logical name that is mapped by the database administration software to a physical directory where the database tables are located. For your database identifier to have any meaning, you must register the name using your database administration software. (The process of registration varies from platform to platform.)
All this information is combined into one string, the "database URL." e.g., to connect through the ODBC subprotocol to a database identified as "emp" the database URL could be:
String dbUrl = "jdbc:odbc:emp";
Then use it like that
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
|
|
|