JDBC in java
JDBC in java
JDBC stands for Java Database Connectivity, which is a standard Java API
for database-independent connectivity between the Java programming
language and a wide range of databases.
The JDBC API consists of classes and methods that are used to perform
various operations like: connect, read, write and store data in the
database.
JDBC Architecture:
The JDBC API supports both two-tier and three-tier processing models for
database access. JDBC Architecture consists of two layers:
The JDBC driver manager ensures that the correct driver is used to access
each data source. The driver manager is capable of supporting multiple
concurrent drivers connected to multiple heterogeneous databases.
JDBC Driver
JDBC Driver is a software component that enables java application to
interact with the database. There are 4 types of JDBC drivers:
Advantage
• Easy to use
Disadvantage
• Slow execution time
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
Disadvantage
This driver translates the JDBC calls into a database server independent
and Middleware server-specific calls. Middleware server further translates
JDBC calls into database specific calls. It is fully written in java.
Advantage
Disadvantage
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:
Disadvantage:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
( "jdbc:oracle:thin:@localhost:1521:xe", "system", "password");
Statement stmt=con.createStatement();
con.close();
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+"
"+rs.getString(3));
}
catch(Exception e)
{
System.out.println(e);
}
}
}