SlideShare a Scribd company logo
1 of 27
JDBC
SAMRAT ASHOK TECHNOLOGICAL
INSTITUTE VIDISHA (M.P.)
SUBMITTED TO:-
MR. GAGAN VISHWAKARMA
(Assistant professor)
SUBMITTED BY:-
SUMIT KUSHWAH
(0108CS131054)
ALBEL SINGH BHARGAV
(0108CS131005)
Introduction to JDBC
http://www.java2all.com
JDBC - Java Database Connectivity.
 The term JDBC unofficially stand for java
database connectivity
 JDBC provides API or Protocol to interact
with different databases.
 It is an API(Application programmiing
interface).
 Class for an specific pupose is called an
API
Connection
http://www.java2all.com
JDBC have so many classes and interfaces
that allow a java application to send request
made by user to any specific DBMS(Data Base
Management System).
JDBC is a bridge between java application and
database
Jdbc is developed by java soft
DEFINITION
JDBC Specification
 Different version of JDBC has different
specification as under.
 JDBC 1.0 - it provides basic functionality of
JDBC.
 JDBC 2.0 - JDBC 3.0 - JDBC 4.0
- it provides so many extra features like Auto
loading of the driver interface.
JDBC Architecture:
 As we all know now that driver is required to
communicate with database.
 JDBC API provides classes and interfaces to
handle request made by user and response made by
database.
 Some of the important JDBC API are as under.
 DriverManager Driver
 Connection Statement
 PreparedStatement CallableStatement
 ResultSet DatabaseMetaData
 ResultSetMetaData
JDBC NETWORK
JDBC DRIVER’S
 (1) Type 1 Driver : JDBC-ODBC Bridge.
 (2) Type 2 Driver : Native-API Driver
(Partly Java driver).
 (3) Type 3 Driver : Network-Protocol
Driver (Pure Java driver for database Middleware).
 (4) Type 4 Driver : Native-Protocol Driver
(Pure Java driver directly connected to database
Type 1 Driver: JDBC-ODBC Bridge :-
 The JDBC type 1 driver which is also known as a
JDBC-ODBC Bridge is a convert JDBC methods
into ODBC function calls.
 Sun provides a JDBC-ODBC Bridge driver by
“sun.jdbc.odbc.JdbcOdbcDriver”.
Architecture Diagram:
Type 4 Driver: Native-Protocol Driver
 The JDBC type 4 driver converts JDBC method
calls directly into the vendor specific database
protocol and in between do not need to be
converted any other formatted system so this is the
fastest way to communicate quires to DBMS and it
is completely written in JAVA because of that this
is also known as the “direct to database Pure JAVA
driver”.
 Approx 56 company have 128 driver
Architecture Diagram:
Steps required to develop jdbc application
 1.Import the required packages
 2.load and register the driver
 3.open the connection to the database
 4.Create Statement Object
 5.Exequte the query
 6.process the result
 7.Disconnect with the database
1.Import packages
 The fisrt step in jdbc programming is to import the
packages to be used by our application for
communicating with the database. Java provide us 2
packages for jdbc
 1.java.sql (Connected Architecture)
 2.javax.sql (Disonnected Architecture)
2.Load and Register the driver
 1.The second and one of the most important step in
jdbc is to tell jvm which driver we want to use for
our application connectivity to the database this
step is called loading and registring the driver
 2.static class forname() .
 3. prototype :-
Public static class forname(String)throws
ClassNotFoundException
3. Opening the Connection to the database
 1.The third step in communicating with the database
is to obtain the connection and this is done by using
the method getConnection belonging to
driverManager class
 2.prototype:-
public static Connection
getConnection(String,String,String)throws
SQLException
ARGUMENT
Sample call:-
Connection
conn=DriverManager.getConnection(“jdbc:oracle:thin
:@//sumit-pc:1521/XE","hr","sati");)
4.Creating Statement Object:
 Once we connected to the database the next step is
to send queries to the database but to do this we
first have to acquire an object of Statement
Interface
 To do this we call the method createStatement()
 Prototype:-
Public Statement
createStatement()throwsSQLException
Statement st=conn.createStatement();
5.Executing Queries
 Once we have obtain stmt object,the next task is
communicate with database
 There are two method for this
 1.public ResultSet
exequteQuery(String)ThrowsSQLException
 2.public int executeUpdate(String)
ThrowsSQLException
6.Fetch and process the result
 In this step we retrive and process the row ‘s which
have been return from the database
 1.Public boolean next()throws SQLException
 2.public xxx getxxx(String column) throws
SQLException
7.Disconnect with the database
 1.public void close() throws SQLException
Sample program
25
import java.sql.*;
class MyJdbcCode1
{ public static void main(String []args)
{ try
{ Class.forName("oracle.jdbc.OracleDriver");
System.out.println("Driver loadedd");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@//sumit-
pc:1521/XE","hr","sati");
System.out.println("connected to the data base");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select FIRST_NAME,LAST_NAME from
EMPLOYEES");
while(rs.next())
{
String name1=rs.getString("FIRST_NAME");
String name2=rs.getString("LAST_NAME");
System.out.println(name1+"t"+name2);
}
Sample program(cont)
26
conn.close();
}
catch(ClassNotFoundException cns)
{
System.out.println("class no found"+cns.getMessage());
System.exit(1);
}
catch(SQLException sq)
{
System.out.println("error:"+sq.getMessage());
System.exit(1);
}
}
}
Comment’s and Query
 If any-

More Related Content

What's hot

Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 

What's hot (20)

Jdbc
JdbcJdbc
Jdbc
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
jdbc document
jdbc documentjdbc document
jdbc document
 
JDBC Architecture and Drivers
JDBC Architecture and DriversJDBC Architecture and Drivers
JDBC Architecture and Drivers
 
java Jdbc
java Jdbc java Jdbc
java Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
JDBC
JDBCJDBC
JDBC
 
JDBC
JDBCJDBC
JDBC
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 

Viewers also liked

Tema 6: Perdidas Mecanicas
Tema 6: Perdidas MecanicasTema 6: Perdidas Mecanicas
Tema 6: Perdidas Mecanicas
shoyas
 

Viewers also liked (13)

Highwaybeautificationwildflowerfl2015
Highwaybeautificationwildflowerfl2015Highwaybeautificationwildflowerfl2015
Highwaybeautificationwildflowerfl2015
 
Lignes directrices pour l évaluation des eaux ra-eaux-minerales
Lignes directrices pour l évaluation des eaux ra-eaux-mineralesLignes directrices pour l évaluation des eaux ra-eaux-minerales
Lignes directrices pour l évaluation des eaux ra-eaux-minerales
 
Dragana densitometry 2nd-behydroday_v2
Dragana densitometry 2nd-behydroday_v2Dragana densitometry 2nd-behydroday_v2
Dragana densitometry 2nd-behydroday_v2
 
HYDRO 2013_Pradyumna
HYDRO 2013_PradyumnaHYDRO 2013_Pradyumna
HYDRO 2013_Pradyumna
 
David m daggett cpa working as a tax manager
David m daggett cpa   working as a tax managerDavid m daggett cpa   working as a tax manager
David m daggett cpa working as a tax manager
 
Presentation Of Strategic Investment Luwu
Presentation Of Strategic Investment LuwuPresentation Of Strategic Investment Luwu
Presentation Of Strategic Investment Luwu
 
Inspectieproces Waterschap Peel- en Maasvallei
Inspectieproces Waterschap Peel- en MaasvalleiInspectieproces Waterschap Peel- en Maasvallei
Inspectieproces Waterschap Peel- en Maasvallei
 
4th Period Game Design Powerpoint
4th Period Game Design Powerpoint4th Period Game Design Powerpoint
4th Period Game Design Powerpoint
 
Mario Macaluso resume
Mario Macaluso resumeMario Macaluso resume
Mario Macaluso resume
 
Emmanuel hydrometrie
Emmanuel  hydrometrieEmmanuel  hydrometrie
Emmanuel hydrometrie
 
Michael J. Anderson Congressional Testimony
Michael J. Anderson Congressional TestimonyMichael J. Anderson Congressional Testimony
Michael J. Anderson Congressional Testimony
 
Reactions Successives, etude de l'influence des conditions operatoires sur la...
Reactions Successives, etude de l'influence des conditions operatoires sur la...Reactions Successives, etude de l'influence des conditions operatoires sur la...
Reactions Successives, etude de l'influence des conditions operatoires sur la...
 
Tema 6: Perdidas Mecanicas
Tema 6: Perdidas MecanicasTema 6: Perdidas Mecanicas
Tema 6: Perdidas Mecanicas
 

Similar to Jdbc new

Similar to Jdbc new (20)

JDBC
JDBCJDBC
JDBC
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
jdbc
jdbcjdbc
jdbc
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.ppt
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
 
Jdbc
JdbcJdbc
Jdbc
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
Java Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptxJava Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptx
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Jdbc new

  • 2. SAMRAT ASHOK TECHNOLOGICAL INSTITUTE VIDISHA (M.P.) SUBMITTED TO:- MR. GAGAN VISHWAKARMA (Assistant professor) SUBMITTED BY:- SUMIT KUSHWAH (0108CS131054) ALBEL SINGH BHARGAV (0108CS131005)
  • 4. JDBC - Java Database Connectivity.  The term JDBC unofficially stand for java database connectivity  JDBC provides API or Protocol to interact with different databases.  It is an API(Application programmiing interface).  Class for an specific pupose is called an API
  • 6. http://www.java2all.com JDBC have so many classes and interfaces that allow a java application to send request made by user to any specific DBMS(Data Base Management System). JDBC is a bridge between java application and database Jdbc is developed by java soft DEFINITION
  • 7. JDBC Specification  Different version of JDBC has different specification as under.  JDBC 1.0 - it provides basic functionality of JDBC.  JDBC 2.0 - JDBC 3.0 - JDBC 4.0 - it provides so many extra features like Auto loading of the driver interface.
  • 8. JDBC Architecture:  As we all know now that driver is required to communicate with database.  JDBC API provides classes and interfaces to handle request made by user and response made by database.  Some of the important JDBC API are as under.  DriverManager Driver  Connection Statement  PreparedStatement CallableStatement  ResultSet DatabaseMetaData  ResultSetMetaData
  • 10. JDBC DRIVER’S  (1) Type 1 Driver : JDBC-ODBC Bridge.  (2) Type 2 Driver : Native-API Driver (Partly Java driver).  (3) Type 3 Driver : Network-Protocol Driver (Pure Java driver for database Middleware).  (4) Type 4 Driver : Native-Protocol Driver (Pure Java driver directly connected to database
  • 11. Type 1 Driver: JDBC-ODBC Bridge :-  The JDBC type 1 driver which is also known as a JDBC-ODBC Bridge is a convert JDBC methods into ODBC function calls.  Sun provides a JDBC-ODBC Bridge driver by “sun.jdbc.odbc.JdbcOdbcDriver”.
  • 13. Type 4 Driver: Native-Protocol Driver  The JDBC type 4 driver converts JDBC method calls directly into the vendor specific database protocol and in between do not need to be converted any other formatted system so this is the fastest way to communicate quires to DBMS and it is completely written in JAVA because of that this is also known as the “direct to database Pure JAVA driver”.  Approx 56 company have 128 driver
  • 15. Steps required to develop jdbc application  1.Import the required packages  2.load and register the driver  3.open the connection to the database  4.Create Statement Object  5.Exequte the query  6.process the result  7.Disconnect with the database
  • 16. 1.Import packages  The fisrt step in jdbc programming is to import the packages to be used by our application for communicating with the database. Java provide us 2 packages for jdbc  1.java.sql (Connected Architecture)  2.javax.sql (Disonnected Architecture)
  • 17. 2.Load and Register the driver  1.The second and one of the most important step in jdbc is to tell jvm which driver we want to use for our application connectivity to the database this step is called loading and registring the driver  2.static class forname() .  3. prototype :- Public static class forname(String)throws ClassNotFoundException
  • 18. 3. Opening the Connection to the database  1.The third step in communicating with the database is to obtain the connection and this is done by using the method getConnection belonging to driverManager class  2.prototype:- public static Connection getConnection(String,String,String)throws SQLException
  • 21. 4.Creating Statement Object:  Once we connected to the database the next step is to send queries to the database but to do this we first have to acquire an object of Statement Interface  To do this we call the method createStatement()  Prototype:- Public Statement createStatement()throwsSQLException Statement st=conn.createStatement();
  • 22. 5.Executing Queries  Once we have obtain stmt object,the next task is communicate with database  There are two method for this  1.public ResultSet exequteQuery(String)ThrowsSQLException  2.public int executeUpdate(String) ThrowsSQLException
  • 23. 6.Fetch and process the result  In this step we retrive and process the row ‘s which have been return from the database  1.Public boolean next()throws SQLException  2.public xxx getxxx(String column) throws SQLException
  • 24. 7.Disconnect with the database  1.public void close() throws SQLException
  • 25. Sample program 25 import java.sql.*; class MyJdbcCode1 { public static void main(String []args) { try { Class.forName("oracle.jdbc.OracleDriver"); System.out.println("Driver loadedd"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@//sumit- pc:1521/XE","hr","sati"); System.out.println("connected to the data base"); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("select FIRST_NAME,LAST_NAME from EMPLOYEES"); while(rs.next()) { String name1=rs.getString("FIRST_NAME"); String name2=rs.getString("LAST_NAME"); System.out.println(name1+"t"+name2); }
  • 26. Sample program(cont) 26 conn.close(); } catch(ClassNotFoundException cns) { System.out.println("class no found"+cns.getMessage()); System.exit(1); } catch(SQLException sq) { System.out.println("error:"+sq.getMessage()); System.exit(1); } } }