SlideShare una empresa de Scribd logo
1 de 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-

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Destacado

Highwaybeautificationwildflowerfl2015
Highwaybeautificationwildflowerfl2015Highwaybeautificationwildflowerfl2015
Highwaybeautificationwildflowerfl2015cprocopiou
 
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 managerDavid M Daggett CPA
 
Presentation Of Strategic Investment Luwu
Presentation Of Strategic Investment LuwuPresentation Of Strategic Investment Luwu
Presentation Of Strategic Investment LuwuBP3M_LUWU
 
4th Period Game Design Powerpoint
4th Period Game Design Powerpoint4th Period Game Design Powerpoint
4th Period Game Design PowerpointAlijah253
 
Michael J. Anderson Congressional Testimony
Michael J. Anderson Congressional TestimonyMichael J. Anderson Congressional Testimony
Michael J. Anderson Congressional TestimonyAndersonIndianLaw
 
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...Nicolas JOUVE
 
Tema 6: Perdidas Mecanicas
Tema 6: Perdidas MecanicasTema 6: Perdidas Mecanicas
Tema 6: Perdidas Mecanicasshoyas
 

Destacado (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 a Jdbc new

Similar a 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
 

Último

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 2024The Digital Insurer
 
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...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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...Neo4j
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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?Antenna Manufacturer Coco
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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.pdfsudhanshuwaghmare1
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Último (20)

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
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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); } } }