JDBC Java
JDBC Java
We can use JDBC API to handle database using Java program and can perform the
following activities:
C
method calls into the ODBC function calls. This is now discouraged because of thin driver.
Advantages:
o easy to use.
o can be easily connected to any database.
Disadvantages:
o Performance degraded because JDBC method call is converted into the ODBC function
calls.
o The ODBC driver needs to be installed on the client machine.
2) Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls
into native calls of the database API. It is not written entirely in java.
Advantage:
o performance upgraded than JDBC-ODBC bridge driver.
Disadvantage:
o The Native driver needs to be installed on each client machine.
o The Vendor client library needs to be installed on client machine.
Disadvantages:
o Network support is required on client machine.
o Requires database-specific coding to be done in the middle tier.
o Maintenance of Network Protocol driver becomes costly because it requires database-
specific coding to be done in the middle tier.
4) Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is
known as thin driver. It is fully written in Java language.
Advantage:
o Better performance than all other drivers.
o No software is required at client side or server side.
Disadvantage:
o Drivers depend on the Database.
Class.forName("oracle.jdbc.driver.OracleDriver");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
import java.sql.*;
class OracleCon
{
public static void main(String args[])
{
try
{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
while(rs.next())
}catch(Exception e)
{
System.out.println(e);
}
}
}