SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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

Weitere ähnliche Inhalte

Was ist angesagt?

JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 

Was ist angesagt? (20)

JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Database connect
Database connectDatabase connect
Database connect
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
JDBC
JDBCJDBC
JDBC
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 

Andere mochten auch

프로세스 관리
프로세스 관리프로세스 관리
프로세스 관리
jeiger
 

Andere mochten auch (14)

Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
프로세스 관리
프로세스 관리프로세스 관리
프로세스 관리
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
Jdbc
JdbcJdbc
Jdbc
 
PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Cultures of india
Cultures of indiaCultures of india
Cultures of india
 
India
IndiaIndia
India
 
Indian culture
Indian cultureIndian culture
Indian culture
 
INCREDIBLE INDIA
INCREDIBLE INDIAINCREDIBLE INDIA
INCREDIBLE INDIA
 
CULTURES OF INDIA
CULTURES OF INDIACULTURES OF INDIA
CULTURES OF INDIA
 
India Presentation
India PresentationIndia Presentation
India Presentation
 
Indian culture
Indian cultureIndian culture
Indian culture
 

Ähnlich wie Jdbc api

jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
phanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
leminhvuong
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 

Ähnlich wie Jdbc api (20)

Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Advance Java Practical file
Advance Java Practical fileAdvance Java Practical file
Advance Java Practical file
 
Lecture17
Lecture17Lecture17
Lecture17
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
 
JDBC
JDBCJDBC
JDBC
 
Advance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-databaseAdvance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-database
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC
JDBCJDBC
JDBC
 
Java beans
Java beansJava beans
Java beans
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
JDBC (2).ppt
JDBC (2).pptJDBC (2).ppt
JDBC (2).ppt
 

Mehr von kamal kotecha

Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 

Mehr von kamal kotecha (19)

Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Java rmi
Java rmiJava rmi
Java rmi
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Jsp element
Jsp elementJsp element
Jsp element
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Interface
InterfaceInterface
Interface
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Class method
Class methodClass method
Class method
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Control statements
Control statementsControl statements
Control statements
 
Jsp myeclipse
Jsp myeclipseJsp myeclipse
Jsp myeclipse
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

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