Concept of JDBC
Concept of JDBC
Type-1 driver allows an application to access the database through ODBC driver. Here ODBC
acts as a mediator between the
jdbc driver and vendors client library.
e.g. ODBC Bridge
Drawbacks:
•ODBC binary code must be loaded on each client.
•Transaction overhead between JDBC and ODBC.
•It doesn’t support all features of Java.
•It works only under Microsoft, SUN operating systems.
Type II Driver - Native-API Partly Java Driver
It converts jdbc calls into calls on clientAPI for dbms. The driver directly communicates with database servers
and therefore some
database client software must be loaded on each client machine and limiting its usefulness for internet.
e.g. Intersolv Oracle Driver, WebLogic drivers
Drawbacks:
•Some database client software must be loaded on each client machine
•Limited functionality
Type III Driver - Net-Protocol All-Java Driver
It is completely implemented in java, hence it is called pure java driver. It translates the jdbc
calls into vendor’s specific protocol which is translated into dbms protocol by a middleware
server.
e.g. Symantec DB
Drawbacks:
It does not support all network protocols.
Every time the net driver is based on other network protocols.
Type IV Driver - Native-Protocol All-Java Driver
Here the driver uses network protocol this protocol is already built-into the database engine;
here the driver talks directly to the database using java sockets. This driver is better than all
other drivers, because this driver supports all network protocols.
Use Java networking libraries to talk directly to database engines
Only disadvantage: need to download a new driver for each database engine
e.g. Oracle, MYSQL
Brief Overview of JDBC Process
Res ultSet
1. Load the JDBC driver
When a driver class is first loaded, it registers itself with the driver Manager Therefore, to
register a driver, just load it!
Example:
String driver = “sun.jdbc.odbc.JdbcOdbcDriver”;
Class.forName(driver);
2. Define the Connection URL
jdbc:subprotocol:source
each driver has its own subprotocol
each subprotocol has its own syntax for the source
jdbc:odbc:DataSource
e.g. jdbc:odbc:Northwind
jdbc:msql://host[:port]/database
e.g. jdbc:msql://foo.nowhere.com:4333/accounting
This statement creates a Statement object, stmt that can pass SQL statements to the DBMS
using connection, con.
5. Execute a query
Execute a SQL query such as SELECT, INSERT, DELETE, UPDATE Example
String SelectStudent= "select * from STUDENT";
6. Process the results
A ResultSet provides access to a table of data generated by executing a Statement.
Only one ResultSet per Statement can be open at once.
The table rows are retrieved in sequence.
A ResultSet maintains a cursor pointing to its current row of data.
The 'next' method moves the cursor to the next row.
7. Close the Connection
connection.close();
– Since opening a connection is expensive, postpone this step if additional database operations
are expected
THANK YOU…