Professional Documents
Culture Documents
Database
JDBC Three Tier Architecture
The JDBC API stands for Java Database Connectivity Application Programming Interface. It
allows an application written in java to communicate and interacts with database.
The JDBC API defines various classes and interfaces to communicate with database.
The java.sql package contains set of classes and interfaces that are used to
communicate with database.
Interface Purpose
Driver Is used to create a connection object using connect()
method.
Connection Is used to monitor and maintain database sessions.
createStatement() method is used create statement.
Class Purpose
DriverManager Is used to manage multiple drivers. And also used to
load and register the JDBC drivers and establish
connection with database. The getconnection() method
of DriverManager class is used to create connection
object.
The JDBC driver test suite helps you to determine that JDBC drivers will run your program. These
tests are not comprehensive or exhaustive, but they do exercise many of the important features in
the JDBC API.
3) JDBC-ODBC Bridge :
The Java Software bridge provides JDBC access via ODBC drivers. Note that you need to load
ODBC binary code onto each client machine that uses this driver. As a result, the ODBC driver is
most appropriate on a corporate network where client installations are not a major problem, or for
application server code written in Java in a three-tier architecture.
JDBC-ODBC Bridge
Advantages Of JDBC.
Disadvantages Of JDBC.
JDBC Driver is a software component that enables java application to interact with the
database.
To help you understand what different drivers require, the following driver categorization
system id defined :-
Database
Type 4: Native-Protocol, Pure Java Driver
Database
Improves performance
Creating Database
import java.sql.*;
public class dbpreparestmt
{
public static void main(String args[])
{
Connection conn = null;
Statement stmt = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Trying to connect with Database");
conn=DriverManager.getConnection("jdbc:mysql://localhost/jdemo","root","");
System.out.println("Connection Established Successfully");
System.out.println("Trying to insert data in table");
stmt = conn.createStatement();
PreparedStatement pst=conn.prepareStatement("INSERT INTO dhyey
VALUES(?,?,?)");
pst.setInt(1,7057);
pst.setString(2,"raj");
pst.setString(3,"gujrat");
pst.executeUpdate();
System.out.println("Data inserted successfully");
conn.close();
stmt.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}