SlideShare a Scribd company logo
Interface ResultSet
•
•
•
•

public interface ResultSetextends Wrapper
Throws SQLException
{
}
• It is the object of a class that implements java.sql.ResultSet interface
• ResultSet rs=st.executeQuery("select * from students");
• Here executeQuery() returns ResultSet object
Interface result set
ResultSet objects
• ResultSet is a java object in our jdbc application which represents the
records selected from the database table
• Resultset object means it is the object of a class that implements
java.sql.ResultSet interface.
• There are two types of ResultSet interface
• 1. Non Scrollable ResultSet object
• 2. Scrollable ResultSet object
Interface result set
Non Scrollable ResultSet object
• The Resuleset object that allows to access the records only in one
direction (top to bottom), unidirectionally, and squentially is called Non
scrollable ResultSet object.
• The ResultSet object that we have to be worked so far in our all previous
applications is called Non scrollable ResultSet object.
• To create non scrollable result set object
• Statement st=con.createStatement(0;
• ResultSet rs=st.executeQuery(“select * from emp”);
• Resultset object we must go through remaining all the records of ResultSet
object sequentially.’
• When the ResultSet object has more records, this may kill the perfomance
Scrollable ResultSet object
Scrollable ResultSet object
• The ResultSet object that allows to access the record randomly, non
sequentially, bidrectionally and directly is called “Scrollable ResultSet
object”.
• Records of scrollable resultSet objec can be acccessed fastly when
compared to non scrollable resultset object we can go toany record of
scrollable result set object directly without going through its previous
records.
• Based on the parameters that are used to crate statement object, the
statement object takes the decision of creating scrollable or non scrollable
resultSet object.
• Syntax: Statement st=con.createStatement(type,mode);
• ResultSet rs=st.executeQuery(“select * from emp”);
ResultSet types(fields)
• We can set the ResultSet type and concurrency to the Statement objct
while we are creating the Statement object.
• Ex:
1.)createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR
_READ_ONLY);
• 2)
prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CO
NCUR_READ_ONLY);
ResultSet type( fields)
• static int TYPE_FORWARD_ONLY
• The constant indicating the type for
a ResultSet object whose cursor may move
only forward.
ResultSet type( fields)
• static int TYPE_SCROLL_INSENSITIVE
• The constant indicating the type for
a ResultSet object that is scrollable but
generally not sensitive to changes to the data
that underlies the ResultSet.
ResultSet type( fields)
• static int TYPE_SCROLL_SENSITIVE
• The constant indicating the type for
a ResultSet object that is scrollable and
generally sensitive to changes to the data that
underlies the ResultSet.
ResultSet type( fields)
• TYPE_SCROLL_INSENSITIVE
• static final int TYPE_SCROLL_INSENSITIVE
The constant indicating the type for
a ResultSet object that is scrollable but
generally not sensitive to changes to the data
that underlies the ResultSet.
•
• CONCUR_READ_ONLY
• static final int CONCUR_READ_ONLY
The constant indicating the concurrency mode
for a ResultSet object that may NOT be
updated.
• CONCUR_UPDATABLE
• static final int CONCUR_UPDATABLE
The constant indicating the concurrency mode
for a ResultSet object that may be updated.
•
Example prog on ResultSet Type and
ResultSet Concurrency
•

//Example to demonstrate Scrollable ResultSet

•
•
•
•
•

import java.sql.*;
import java.util.*;
import java.io.*;
public class ScrollableRSEx1 {
public static void main(String s[]) throws Exception {

•
•

Driver d= (Driver) ( Class.forName(

•
•
•

Properties p=new Properties ();
p.put("user","root");
p.put("password","admin");

•
•

Connection con=d.connect(

"com.mysql.jdbc.Driver").newInstance());

"jdbc:mysql://localhost:3306/test",p);
•
•

Statement st= con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);

•
•
•

String query="select * from emp where deptno=10";
•
•

ResultSet rs= st.executeQuery(query);
//Now the cursor of resultset will at beforeFirst & the result set produced is scrollable

•

System.out.println("EmpNotName");

•
•
•
•
•

while (rs.next()) {
System.out.print(rs.getInt(1)+"t");
System.out.println(rs.getString(2));
}//while
//Now the cursor of resultset will at afterLast

•

System.out.println("Reading Data, moving the cursor in backward directionn");

•
•
•
•
•
•
•
•
•
•
•

while (rs.previous()){
System.out.print(rs.getInt(1)+"t");
System.out.println(rs.getString(2));
}//while
con.close();
}//main
}//class
/*
EmpNo
Name
2
uday kumar
Reading Data, moving the cursor in backward direction

•

2

•

*/

uday kumar
getMetaData()
ResultSetMetaData getMetaData() throws SQLException
{
}
• Retrieves the number, types and properties of
this ResultSet object's columns.
• How to call
• ResultSetMetaData rsmd=rs.getMetaData();
rs.getString ( ) • rs.getString ( ) –
• The Result set object call a get String (
),returns you a record set into a formatted
string element.
getDouble()
double getDouble(int columnIndex)
{
}
• Retrieves the value of the designated column
in the current row of this ResultSet object as
a double in the Java programming language.
getString()
• String getString(String columnLabel)
• Retrieves the value of the designated column
in the current row of this ResultSet object as
a String in the Java programming language.
getInt()
• int getInt(String columnLabel)
• Retrieves the value of the designated column
in the current row of this ResultSet object as
an int in the Java programming language.
getDouble()
• Retrieves the value of the designated column
in the current row of this ResultSet object as
a double in the Java programming language.
• double getDouble(String columnLabel)
Note:
• We can send only those java objects over the network that are
Serializable.
• In order to make object as Serializable object, the class of the object must
implement java.io.Serializable interface.
• In order to store data of the object in a file, the object must be serializable
object.
• ResultSet object is not Serializable object, so we can not send this object
over the network directly.
• To overcome this problem, there are two solutions
• 1. Use RowSets in the place of ResultSets.
• 2. copy data of ResultSet object to RowSet

More Related Content

PPT
1 - Introduction to PL/SQL
ODP
ER Model in DBMS
PPT
C++ Memory Management
PPT
Aggregate functions
PPT
Oops ppt
PPTX
XML DTD and Schema
PPTX
Java I/O
PPT
Servlet life cycle
1 - Introduction to PL/SQL
ER Model in DBMS
C++ Memory Management
Aggregate functions
Oops ppt
XML DTD and Schema
Java I/O
Servlet life cycle

What's hot (20)

PPTX
Common language runtime clr
PPTX
How to Draw an Effective ER diagram
PDF
Object oriented programming c++
PPT
Java interfaces
PPTX
Chapter-9 Normalization
PDF
Set methods in python
PPTX
Chapter 6 relational data model and relational
PPTX
Method overloading
ODP
Introduction to triggers
ODP
Python Modules
PPTX
Java swing
PDF
Python Data Types (1).pdf
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
[OOP - Lec 18] Static Data Member
PPT
JSP Processing
PPT
Introduction to java beans
PDF
Java I/o streams
PPTX
Hibernate ppt
 
PPTX
Unit 5 java-awt (1)
PPTX
Object Oriented Programming in Java _lecture 1
Common language runtime clr
How to Draw an Effective ER diagram
Object oriented programming c++
Java interfaces
Chapter-9 Normalization
Set methods in python
Chapter 6 relational data model and relational
Method overloading
Introduction to triggers
Python Modules
Java swing
Python Data Types (1).pdf
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
[OOP - Lec 18] Static Data Member
JSP Processing
Introduction to java beans
Java I/o streams
Hibernate ppt
 
Unit 5 java-awt (1)
Object Oriented Programming in Java _lecture 1
Ad

Similar to Interface result set (20)

PPT
Scrollable Updatable
PPT
Scrollable Updatable
PDF
java4th.pdf bilgisayar mühendisliği bölümü
PPTX
Retrieving data from database using result set (1)
PPT
41slideAdvancedDatabaseProgramming.ppt
PDF
Java 1-contd
PPT
Jdbc oracle
PPT
JDBC – Java Database Connectivity
PPTX
Discuss the scrollable result set in jdbc
PPT
4. Database Connectivity using JDBC .ppt
PDF
Java JDBC
PPTX
JDBC ResultSet power point presentation by klu
PPT
KMUTNB - Internet Programming 6/7
PDF
Overview Of JDBC
PPT
JDBC DriversPros and Cons of Each Driver
PPTX
Session 24 - JDBC, Intro to Enterprise Java
PPT
3 database-jdbc(1)
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
PPT
statement interface
Scrollable Updatable
Scrollable Updatable
java4th.pdf bilgisayar mühendisliği bölümü
Retrieving data from database using result set (1)
41slideAdvancedDatabaseProgramming.ppt
Java 1-contd
Jdbc oracle
JDBC – Java Database Connectivity
Discuss the scrollable result set in jdbc
4. Database Connectivity using JDBC .ppt
Java JDBC
JDBC ResultSet power point presentation by klu
KMUTNB - Internet Programming 6/7
Overview Of JDBC
JDBC DriversPros and Cons of Each Driver
Session 24 - JDBC, Intro to Enterprise Java
3 database-jdbc(1)
Java OOP Programming language (Part 8) - Java Database JDBC
statement interface
Ad

More from myrajendra (20)

PPT
Fundamentals
PPT
Data type
PPTX
Hibernate example1
PPTX
Jdbc workflow
PPTX
2 jdbc drivers
PPTX
3 jdbc api
PPTX
4 jdbc step1
PPTX
Dao example
PPTX
Sessionex1
PPTX
Internal
PPTX
3. elements
PPTX
2. attributes
PPTX
1 introduction to html
PPTX
Headings
PPTX
Forms
PPT
Css
PPTX
Views
PPTX
Views
PPTX
Views
PPT
Starting jdbc
Fundamentals
Data type
Hibernate example1
Jdbc workflow
2 jdbc drivers
3 jdbc api
4 jdbc step1
Dao example
Sessionex1
Internal
3. elements
2. attributes
1 introduction to html
Headings
Forms
Css
Views
Views
Views
Starting jdbc

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
 
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
 
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Interface result set

  • 3. • It is the object of a class that implements java.sql.ResultSet interface • ResultSet rs=st.executeQuery("select * from students"); • Here executeQuery() returns ResultSet object
  • 5. ResultSet objects • ResultSet is a java object in our jdbc application which represents the records selected from the database table • Resultset object means it is the object of a class that implements java.sql.ResultSet interface. • There are two types of ResultSet interface • 1. Non Scrollable ResultSet object • 2. Scrollable ResultSet object
  • 7. Non Scrollable ResultSet object • The Resuleset object that allows to access the records only in one direction (top to bottom), unidirectionally, and squentially is called Non scrollable ResultSet object. • The ResultSet object that we have to be worked so far in our all previous applications is called Non scrollable ResultSet object. • To create non scrollable result set object • Statement st=con.createStatement(0; • ResultSet rs=st.executeQuery(“select * from emp”); • Resultset object we must go through remaining all the records of ResultSet object sequentially.’ • When the ResultSet object has more records, this may kill the perfomance
  • 9. Scrollable ResultSet object • The ResultSet object that allows to access the record randomly, non sequentially, bidrectionally and directly is called “Scrollable ResultSet object”. • Records of scrollable resultSet objec can be acccessed fastly when compared to non scrollable resultset object we can go toany record of scrollable result set object directly without going through its previous records. • Based on the parameters that are used to crate statement object, the statement object takes the decision of creating scrollable or non scrollable resultSet object. • Syntax: Statement st=con.createStatement(type,mode); • ResultSet rs=st.executeQuery(“select * from emp”);
  • 10. ResultSet types(fields) • We can set the ResultSet type and concurrency to the Statement objct while we are creating the Statement object. • Ex: 1.)createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR _READ_ONLY); • 2) prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CO NCUR_READ_ONLY);
  • 11. ResultSet type( fields) • static int TYPE_FORWARD_ONLY • The constant indicating the type for a ResultSet object whose cursor may move only forward.
  • 12. ResultSet type( fields) • static int TYPE_SCROLL_INSENSITIVE • The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.
  • 13. ResultSet type( fields) • static int TYPE_SCROLL_SENSITIVE • The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet.
  • 14. ResultSet type( fields) • TYPE_SCROLL_INSENSITIVE • static final int TYPE_SCROLL_INSENSITIVE The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet. •
  • 15. • CONCUR_READ_ONLY • static final int CONCUR_READ_ONLY The constant indicating the concurrency mode for a ResultSet object that may NOT be updated.
  • 16. • CONCUR_UPDATABLE • static final int CONCUR_UPDATABLE The constant indicating the concurrency mode for a ResultSet object that may be updated. •
  • 17. Example prog on ResultSet Type and ResultSet Concurrency • //Example to demonstrate Scrollable ResultSet • • • • • import java.sql.*; import java.util.*; import java.io.*; public class ScrollableRSEx1 { public static void main(String s[]) throws Exception { • • Driver d= (Driver) ( Class.forName( • • • Properties p=new Properties (); p.put("user","root"); p.put("password","admin"); • • Connection con=d.connect( "com.mysql.jdbc.Driver").newInstance()); "jdbc:mysql://localhost:3306/test",p); • • Statement st= con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); • • • String query="select * from emp where deptno=10";
  • 18. • • ResultSet rs= st.executeQuery(query); //Now the cursor of resultset will at beforeFirst & the result set produced is scrollable • System.out.println("EmpNotName"); • • • • • while (rs.next()) { System.out.print(rs.getInt(1)+"t"); System.out.println(rs.getString(2)); }//while //Now the cursor of resultset will at afterLast • System.out.println("Reading Data, moving the cursor in backward directionn"); • • • • • • • • • • • while (rs.previous()){ System.out.print(rs.getInt(1)+"t"); System.out.println(rs.getString(2)); }//while con.close(); }//main }//class /* EmpNo Name 2 uday kumar Reading Data, moving the cursor in backward direction • 2 • */ uday kumar
  • 19. getMetaData() ResultSetMetaData getMetaData() throws SQLException { } • Retrieves the number, types and properties of this ResultSet object's columns. • How to call • ResultSetMetaData rsmd=rs.getMetaData();
  • 20. rs.getString ( ) • rs.getString ( ) – • The Result set object call a get String ( ),returns you a record set into a formatted string element.
  • 21. getDouble() double getDouble(int columnIndex) { } • Retrieves the value of the designated column in the current row of this ResultSet object as a double in the Java programming language.
  • 22. getString() • String getString(String columnLabel) • Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
  • 23. getInt() • int getInt(String columnLabel) • Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language.
  • 24. getDouble() • Retrieves the value of the designated column in the current row of this ResultSet object as a double in the Java programming language. • double getDouble(String columnLabel)
  • 25. Note: • We can send only those java objects over the network that are Serializable. • In order to make object as Serializable object, the class of the object must implement java.io.Serializable interface. • In order to store data of the object in a file, the object must be serializable object. • ResultSet object is not Serializable object, so we can not send this object over the network directly. • To overcome this problem, there are two solutions • 1. Use RowSets in the place of ResultSets. • 2. copy data of ResultSet object to RowSet