SlideShare a Scribd company logo
JDBC APIS




            http://www.java2all.com
Chapter 2



JDBC APIs:



             http://www.java2all.com
JDBC APIs:



             http://www.java2all.com
If any java application or an applet wants to
connect with a database then there are various
classes and interfaces available in java.sql package.

   Depending on the requirements these classes
and interfaces can be used.

   Some of them are list out the below which are
used to perform the various tasks with database as
well as for connection.


                                           http://www.java2all.com
Class or Interface              Description


Java.sql.Connection           Create a connection with specific database


                               The task of DriverManager is to manage the database
Java.sql.DriverManager
                             driver


                               It executes SQL statements for particular connection and
Java.sql.Statement
                             retrieve the results


                               It allows the programmer to create prepared SQL
Java.sql.PreparedStatement
                             statements


Java.sql.CallableStatement    It executes stored procedures


                               This interface provides methods to get result row by row
Java.sql.ResultSet
                             generated by SELECT statements
                                                                       http://www.java2all.com
Now we are going to elobrate each class or
interface in detail with their methods and will give
program for each one in next topic.




                                              http://www.java2all.com
The Connection interface:




                        http://www.java2all.com
The Connection interface used to connect java
application with particular database.

      After crating the connection with database we
can execute SQL statements for that particular
connection using object of Connection and retrieve the
results.

     The interface has few methods that makes
changes to the database temporary or permanently.
The some methods are as given below.


                                            http://www.java2all.com
Method                                      Description
                                          This method frees an object of type Connection from
void close()
                                          database and other JDBC resources.

                                          This method makes all the changes made since the last
void commit()                             commit or rollback permanent. It throws
                                          SQLExeception.
                                          This method creates an object of type Statement for
Statement createStatement()               sending SQL statements to the database. It throws
                                          SQLExeception.

boolean isClosed()                        Return true if the connection is close else return false.

                                          This method creates an object of type
CallableStatement prepareCall(String s)   CallableStatement for calling the stored procedures
                                          from database. It throws SQLExeception.
                                          This method creates an object of type
PreparedStatement                         PrepareStatement for sending dynamic (with or without
prepareStatement(String s)                IN parameter) SQL statements to the database. It
                                          throws SQLExeception.

void rollback()                           This method undoes all changes made to the database.
                                                                                http://www.java2all.com
The example program for Connection interface
and its methods are given in next chapter for different
databases.




                                             http://www.java2all.com
Statement Interface:



                   http://www.java2all.com
The Statement interface is used for to
execute a static query.

    It’s a very simple and easy so it also calls a
“Simple Statement”.

      The statement interface has several methods
for execute the SQL statements and also get the
appropriate result as per the query sent to the
database.

     Some of the most common methods are as
given below
                                              http://www.java2all.com
Method                                    Description

                              This method frees an object of type Statement from
void close()
                              database and other JDBC resources.

                              This method executes the SQL statement specified by s.
boolean execute(String s)
                              The getResultSet() method is used to retrieve the result.

                              This method retrieves the ResultSet that is generated by
ResultSet getResultet()
                              the execute() method.

ResultSet                     This method is used to execute the SQL statement
executeQuery(String s)        specified by s and returns the object of type ResultSet.

                              This method returns the maximum number of rows those
int getMaxRows()
                              are generated by the executeQuery() method.

                              This method executes the SQL statement specified by s.
Int executeUpdate(String s)   The SQL statement may be a SQL insert, update and
                              delete statement.
                                                                        http://www.java2all.com
The example program for Statement interface
and its methods are given in next chapter for different
databases.




                                             http://www.java2all.com
The Prepared Statement Interface:




                            http://www.java2all.com
The Prepared Statement interface is used to
execute a dynamic query (parameterized SQL
statement) with IN parameter.

      IN Parameter:-

            In some situation where we need to pass
different values to an query then such values can be
specified as a “?” in the query and the actual values
can be passed using the setXXX() method at the time
of execution.

Syntax :
setXXX(integer data ,XXX value);            http://www.java2all.com
Where XXX means a data type as per the value
we want to pass in the query.
For example,
String query = "Select * from Data where ID = ? and
Name = ? ";
PreparedStatement ps = con.prepareStatement(query);
         ps.setInt(1, 1);
         ps.setString(2, "Ashutosh Abhangi");
      The Prepared statement interface has several
methods to execute the parameterized SQL statements
and retrieve appropriate result as per the query sent to
the database.
      Some of the most common methods are as given
below                                          http://www.java2all.com
Method                                    Description
                                  This method frees an object of type Prepared Statement from
void close()
                                  database and other JDBC resources.

                                  This method executes the dynamic query in the object of type
boolean execute()                 Prepared Statement.The getResult() method is used to
                                  retrieve the result.
                                  This method is used to execute the dynamic query in the
ResultSet executeQuery()          object of type Prepared Statement and returns the object of
                                  type ResultSet.

                                  This method executes the SQL statement in the object of type
Int executeUpdate()               Prepared Statement. The SQL statement may be a SQL
                                  insert, update and delete statement.

                                The ResultSetMetaData means a deta about the data of
                                ResultSet.This method retrieves an object of type
ResultSetMetaData getMetaData() ResultSetMetaData that contains information about the
                                columns of the ResultSet object that will be return when a
                                query is execute.

                                  This method returns the maximum number of rows those are
int getMaxRows()
                                  generated by the executeQuery() method.
                                                                             http://www.java2all.com
The example program for Prepared Statement
interface and its methods are given in next chapter for
different databases.




                                             http://www.java2all.com

More Related Content

What's hot (20)

PPTX
JDBC ppt
Rohit Jain
 
PPTX
Java Database Connectivity (JDBC)
Pooja Talreja
 
PPTX
Jdbc in servlets
Nuha Noor
 
PDF
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
PDF
JDBC in Servlets
Eleonora Ciceri
 
PPT
Java Database Connectivity
backdoor
 
PPTX
1. java database connectivity (jdbc)
Fad Zulkifli
 
PPT
java jdbc connection
Waheed Warraich
 
PPTX
Java database connectivity
Atul Saurabh
 
PPTX
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
PPT
Java database connectivity with MYSQL
Adil Mehmoood
 
PPT
Java database connectivity
Vaishali Modi
 
PPT
Java Server Pages
BG Java EE Course
 
PPTX
Database connect
Yoga Raja
 
PPTX
Java Servlet
Yoga Raja
 
PPT
JDBC
Ankit Desai
 
PPT
Jsp ppt
Vikas Jagtap
 
PDF
Hibernate Presentation
guest11106b
 
JDBC ppt
Rohit Jain
 
Java Database Connectivity (JDBC)
Pooja Talreja
 
Jdbc in servlets
Nuha Noor
 
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
JDBC in Servlets
Eleonora Ciceri
 
Java Database Connectivity
backdoor
 
1. java database connectivity (jdbc)
Fad Zulkifli
 
java jdbc connection
Waheed Warraich
 
Java database connectivity
Atul Saurabh
 
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Java database connectivity with MYSQL
Adil Mehmoood
 
Java database connectivity
Vaishali Modi
 
Java Server Pages
BG Java EE Course
 
Database connect
Yoga Raja
 
Java Servlet
Yoga Raja
 
Jsp ppt
Vikas Jagtap
 
Hibernate Presentation
guest11106b
 

Viewers also liked (14)

PPTX
프로세스 관리
jeiger
 
PPTX
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
PPTX
3 jdbc api
myrajendra
 
PPTX
Jdbc
Yamuna Devi
 
PPT
PULSE CODE MODULATION (PCM)
vishnudharan11
 
PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PPTX
Cultures of india
Gowtham Raja
 
PPT
India
guestc9f3d3
 
PPSX
Indian culture
sowju1830
 
PPT
INCREDIBLE INDIA
Biswajit Ghosh
 
PPSX
CULTURES OF INDIA
Jenisha Domadia
 
PPTX
India Presentation
anujfun
 
PPTX
Indian culture
Aayupta Mohanty
 
프로세스 관리
jeiger
 
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
3 jdbc api
myrajendra
 
PULSE CODE MODULATION (PCM)
vishnudharan11
 
Java servlet life cycle - methods ppt
kamal kotecha
 
Cultures of india
Gowtham Raja
 
Indian culture
sowju1830
 
INCREDIBLE INDIA
Biswajit Ghosh
 
CULTURES OF INDIA
Jenisha Domadia
 
India Presentation
anujfun
 
Indian culture
Aayupta Mohanty
 
Ad

Similar to Jdbc api (20)

PPT
Executing Sql Commands
phanleson
 
PPT
Executing Sql Commands
leminhvuong
 
PDF
java4th.pdf bilgisayar mühendisliği bölümü
Smeyyeztrk10
 
PDF
Java 1-contd
Mukesh Tekwani
 
PDF
Lecture17
vantinhkhuc
 
PPS
Jdbc session02
Niit Care
 
PDF
Presentation for java data base connectivity
kanjariya006
 
PPTX
JDBC
Balwinder Kumar
 
PDF
Jdbc 1
Tuan Ngo
 
PDF
Core Java Programming Language (JSE) : Chapter XIII - JDBC
WebStackAcademy
 
PPTX
Jdbc presentation
nrjoshiee
 
PPTX
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
tirthasurani118866
 
PPT
statement interface
khush_boo31
 
PPTX
Jdbc Java Programming
chhaichivon
 
PDF
Java JDBC
Jussi Pohjolainen
 
PPT
JDBC for CSQL Database
jitendral
 
PPTX
Jdbc ppt
AISHWARIYA1S
 
PPT
Jdbc
lathasiva
 
PPT
Jdbc oracle
yazidds2
 
Executing Sql Commands
phanleson
 
Executing Sql Commands
leminhvuong
 
java4th.pdf bilgisayar mühendisliği bölümü
Smeyyeztrk10
 
Java 1-contd
Mukesh Tekwani
 
Lecture17
vantinhkhuc
 
Jdbc session02
Niit Care
 
Presentation for java data base connectivity
kanjariya006
 
Jdbc 1
Tuan Ngo
 
Core Java Programming Language (JSE) : Chapter XIII - JDBC
WebStackAcademy
 
Jdbc presentation
nrjoshiee
 
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
tirthasurani118866
 
statement interface
khush_boo31
 
Jdbc Java Programming
chhaichivon
 
JDBC for CSQL Database
jitendral
 
Jdbc ppt
AISHWARIYA1S
 
Jdbc
lathasiva
 
Jdbc oracle
yazidds2
 
Ad

More from kamal kotecha (19)

PPS
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
PPTX
Network programming in java - PPT
kamal kotecha
 
PPS
Java rmi example program with code
kamal kotecha
 
PPS
Java rmi
kamal kotecha
 
PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PPS
Java Exception handling
kamal kotecha
 
PPS
JSP Error handling
kamal kotecha
 
PPS
Jsp element
kamal kotecha
 
PPS
Jsp chapter 1
kamal kotecha
 
PPS
String and string buffer
kamal kotecha
 
PPS
Wrapper class
kamal kotecha
 
PPS
Packages and inbuilt classes of java
kamal kotecha
 
PPS
Interface
kamal kotecha
 
PPS
Inheritance chepter 7
kamal kotecha
 
PPS
Class method
kamal kotecha
 
PPS
Introduction to class in java
kamal kotecha
 
PPS
Control statements
kamal kotecha
 
PPTX
Jsp myeclipse
kamal kotecha
 
PPTX
basic core java up to operator
kamal kotecha
 
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Network programming in java - PPT
kamal kotecha
 
Java rmi example program with code
kamal kotecha
 
Java rmi
kamal kotecha
 
Jdbc architecture and driver types ppt
kamal kotecha
 
Java Exception handling
kamal kotecha
 
JSP Error handling
kamal kotecha
 
Jsp element
kamal kotecha
 
Jsp chapter 1
kamal kotecha
 
String and string buffer
kamal kotecha
 
Wrapper class
kamal kotecha
 
Packages and inbuilt classes of java
kamal kotecha
 
Interface
kamal kotecha
 
Inheritance chepter 7
kamal kotecha
 
Class method
kamal kotecha
 
Introduction to class in java
kamal kotecha
 
Control statements
kamal kotecha
 
Jsp myeclipse
kamal kotecha
 
basic core java up to operator
kamal kotecha
 

Recently uploaded (20)

PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 

Jdbc api

  • 1. JDBC APIS http://www.java2all.com
  • 2. Chapter 2 JDBC APIs: http://www.java2all.com
  • 3. JDBC APIs: http://www.java2all.com
  • 4. If any java application or an applet wants to connect with a database then there are various classes and interfaces available in java.sql package. Depending on the requirements these classes and interfaces can be used. Some of them are list out the below which are used to perform the various tasks with database as well as for connection. http://www.java2all.com
  • 5. Class or Interface Description Java.sql.Connection Create a connection with specific database The task of DriverManager is to manage the database Java.sql.DriverManager driver It executes SQL statements for particular connection and Java.sql.Statement retrieve the results It allows the programmer to create prepared SQL Java.sql.PreparedStatement statements Java.sql.CallableStatement It executes stored procedures This interface provides methods to get result row by row Java.sql.ResultSet generated by SELECT statements http://www.java2all.com
  • 6. Now we are going to elobrate each class or interface in detail with their methods and will give program for each one in next topic. http://www.java2all.com
  • 7. The Connection interface: http://www.java2all.com
  • 8. The Connection interface used to connect java application with particular database. After crating the connection with database we can execute SQL statements for that particular connection using object of Connection and retrieve the results. The interface has few methods that makes changes to the database temporary or permanently. The some methods are as given below. http://www.java2all.com
  • 9. Method Description This method frees an object of type Connection from void close() database and other JDBC resources. This method makes all the changes made since the last void commit() commit or rollback permanent. It throws SQLExeception. This method creates an object of type Statement for Statement createStatement() sending SQL statements to the database. It throws SQLExeception. boolean isClosed() Return true if the connection is close else return false. This method creates an object of type CallableStatement prepareCall(String s) CallableStatement for calling the stored procedures from database. It throws SQLExeception. This method creates an object of type PreparedStatement PrepareStatement for sending dynamic (with or without prepareStatement(String s) IN parameter) SQL statements to the database. It throws SQLExeception. void rollback() This method undoes all changes made to the database. http://www.java2all.com
  • 10. The example program for Connection interface and its methods are given in next chapter for different databases. http://www.java2all.com
  • 11. Statement Interface: http://www.java2all.com
  • 12. The Statement interface is used for to execute a static query. It’s a very simple and easy so it also calls a “Simple Statement”. The statement interface has several methods for execute the SQL statements and also get the appropriate result as per the query sent to the database. Some of the most common methods are as given below http://www.java2all.com
  • 13. Method Description This method frees an object of type Statement from void close() database and other JDBC resources. This method executes the SQL statement specified by s. boolean execute(String s) The getResultSet() method is used to retrieve the result. This method retrieves the ResultSet that is generated by ResultSet getResultet() the execute() method. ResultSet This method is used to execute the SQL statement executeQuery(String s) specified by s and returns the object of type ResultSet. This method returns the maximum number of rows those int getMaxRows() are generated by the executeQuery() method. This method executes the SQL statement specified by s. Int executeUpdate(String s) The SQL statement may be a SQL insert, update and delete statement. http://www.java2all.com
  • 14. The example program for Statement interface and its methods are given in next chapter for different databases. http://www.java2all.com
  • 15. The Prepared Statement Interface: http://www.java2all.com
  • 16. The Prepared Statement interface is used to execute a dynamic query (parameterized SQL statement) with IN parameter. IN Parameter:- In some situation where we need to pass different values to an query then such values can be specified as a “?” in the query and the actual values can be passed using the setXXX() method at the time of execution. Syntax : setXXX(integer data ,XXX value); http://www.java2all.com
  • 17. Where XXX means a data type as per the value we want to pass in the query. For example, String query = "Select * from Data where ID = ? and Name = ? "; PreparedStatement ps = con.prepareStatement(query); ps.setInt(1, 1); ps.setString(2, "Ashutosh Abhangi"); The Prepared statement interface has several methods to execute the parameterized SQL statements and retrieve appropriate result as per the query sent to the database. Some of the most common methods are as given below http://www.java2all.com
  • 18. Method Description This method frees an object of type Prepared Statement from void close() database and other JDBC resources. This method executes the dynamic query in the object of type boolean execute() Prepared Statement.The getResult() method is used to retrieve the result. This method is used to execute the dynamic query in the ResultSet executeQuery() object of type Prepared Statement and returns the object of type ResultSet. This method executes the SQL statement in the object of type Int executeUpdate() Prepared Statement. The SQL statement may be a SQL insert, update and delete statement. The ResultSetMetaData means a deta about the data of ResultSet.This method retrieves an object of type ResultSetMetaData getMetaData() ResultSetMetaData that contains information about the columns of the ResultSet object that will be return when a query is execute. This method returns the maximum number of rows those are int getMaxRows() generated by the executeQuery() method. http://www.java2all.com
  • 19. The example program for Prepared Statement interface and its methods are given in next chapter for different databases. http://www.java2all.com