GANDHINGAR INSTITUTE OF
TECHNOLOGY
INFORMATION TECHNOLOGY DEPARTMENT
ADVANCED JAVA
CREATING JDBC CONNECTION
Enrollment no: 150120116047
Name: Prince Paneliya
Guided By: Prof. Prashant Jani
What is JDBC?
JDBC provides Java applications with access to
most database systems via SQl.
JDBC acronomy of java database connectivity
through Sun Microsystems claims that it is not
the full form.
JDBC is a standard java API for independence
database connection between a java program
and wide range of relational database.
Database Connectivity
Before APIs like JDBC and ODBC, database
connectivity was tedious
Each database vendor provided a function library
for accessing their database
The connectivity library was proprietary.
If the database vendor changed for the application,
the data access portions had to be rewritten
Types of JDBC Drivers
There are four types of jDBC Drivers.
Type 1 - JDBC-ODBC Bridge
Type 2 - JDBC-Native Bridge
Type 3 - JDBC-Net Bridge
Type 4 - Direct JDBC Driver
JDBC-ODBC Bridge
It runs only on platforms where ODBC is available
ODBC must be configured separately
The JDBC-ODBC bridge driver uses ODBC driver to connect to the
database.
The JDBC-ODBC bridge driver converts JDBC method calls into
the ODBC function calls.
Jdbc
api
Java
application
Jdbc-
odbc
driver
Odbc
driver DataB
ase
Vendor
databa
se
JDBC Native Bridge
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
Java
application
Jdbc api
Native Api
driver
Vendor
database DataBase
JDBC-Net Bridge
 The Network Protocol driver uses middleware that
converts JDBC calls directly or indirectly into the vendor-
specific database protocol.
 It is fully written in java.
Java
Application
Network
Protocol
layer
Middleware
Databas
e
JDBC
Api
Direct JDBC 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.
Java Application
JDBC Api
Thin driver Database
steps to connect JDBC
connection
 There are five steps to connect java
application with the database in java using
JDBC.
1. Register the Driver class.
2. Create the connection object.
3. Create the statement object.
4. Execute the query.
5. Close the connection.
 The forName() method of Class class is used
to register the driver class.
 This method is used to dynamically load the
driver.
syntax:-
Class.forName(“mysql.jdbc.driver.
mysqldriver”);
 The getConnection() method of DriverManager
class is used to establish connection with the
database.
Syntax :-
Connection con =
DriverManager.getConnection(“jd
bc:mysql://localhost:dbname”,”roo
t”,”password”)
 The createStatement() method of Connection
interface is used to create statement.
 The object of statement is responsible to
execute queries with the database.
Syntax:-
Statement
stmt=con.createStatement();
 The executeQuery() method of Statement interface is used to
execute queries to the database.
 This method returns the object of ResultSet that can be used
to get all the records of a table.
Syntax:-
ResultSet rs = stmt.ExecuteQuery(“select *
from table”);
While(rs.next()){
System.out.println(“rs.getInt(1)+“
”+rs.getString(“name”) );
}
 By closing connection object statement and
ResultSet will be closed automatically.
 The close() method of Connection interface is
used to close the connection.
Syntax:-
con.close();
Thank you

creating jdbc connection

  • 1.
    GANDHINGAR INSTITUTE OF TECHNOLOGY INFORMATIONTECHNOLOGY DEPARTMENT ADVANCED JAVA CREATING JDBC CONNECTION Enrollment no: 150120116047 Name: Prince Paneliya Guided By: Prof. Prashant Jani
  • 2.
    What is JDBC? JDBCprovides Java applications with access to most database systems via SQl. JDBC acronomy of java database connectivity through Sun Microsystems claims that it is not the full form. JDBC is a standard java API for independence database connection between a java program and wide range of relational database.
  • 3.
    Database Connectivity Before APIslike JDBC and ODBC, database connectivity was tedious Each database vendor provided a function library for accessing their database The connectivity library was proprietary. If the database vendor changed for the application, the data access portions had to be rewritten
  • 4.
    Types of JDBCDrivers There are four types of jDBC Drivers. Type 1 - JDBC-ODBC Bridge Type 2 - JDBC-Native Bridge Type 3 - JDBC-Net Bridge Type 4 - Direct JDBC Driver
  • 5.
    JDBC-ODBC Bridge It runsonly on platforms where ODBC is available ODBC must be configured separately The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. Jdbc api Java application Jdbc- odbc driver Odbc driver DataB ase Vendor databa se
  • 6.
    JDBC Native Bridge TheNative API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API Java application Jdbc api Native Api driver Vendor database DataBase
  • 7.
    JDBC-Net Bridge  TheNetwork Protocol driver uses middleware that converts JDBC calls directly or indirectly into the vendor- specific database protocol.  It is fully written in java. Java Application Network Protocol layer Middleware Databas e JDBC Api
  • 8.
    Direct JDBC 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. Java Application JDBC Api Thin driver Database
  • 9.
    steps to connectJDBC connection  There are five steps to connect java application with the database in java using JDBC. 1. Register the Driver class. 2. Create the connection object. 3. Create the statement object. 4. Execute the query. 5. Close the connection.
  • 10.
     The forName()method of Class class is used to register the driver class.  This method is used to dynamically load the driver. syntax:- Class.forName(“mysql.jdbc.driver. mysqldriver”);
  • 11.
     The getConnection()method of DriverManager class is used to establish connection with the database. Syntax :- Connection con = DriverManager.getConnection(“jd bc:mysql://localhost:dbname”,”roo t”,”password”)
  • 12.
     The createStatement()method of Connection interface is used to create statement.  The object of statement is responsible to execute queries with the database. Syntax:- Statement stmt=con.createStatement();
  • 13.
     The executeQuery()method of Statement interface is used to execute queries to the database.  This method returns the object of ResultSet that can be used to get all the records of a table. Syntax:- ResultSet rs = stmt.ExecuteQuery(“select * from table”); While(rs.next()){ System.out.println(“rs.getInt(1)+“ ”+rs.getString(“name”) ); }
  • 14.
     By closingconnection object statement and ResultSet will be closed automatically.  The close() method of Connection interface is used to close the connection. Syntax:- con.close();
  • 15.

Editor's Notes

  • #3 JDBC provides Java applications with access to most database systems via SQL