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

What's hot (20)

PPTX
X86 Architecture
IGZ Software house
 
PPT
Runnable interface.34
myrajendra
 
PPT
Introduction & history of dbms
sethu pm
 
PDF
Create table
Nitesh Singh
 
PPTX
DDL And DML
pnp @in
 
PPTX
Xml dtd
HeenaRajput1
 
PPT
PHP variables
Siddique Ibrahim
 
PDF
dbms lab manual
stalinjothi
 
PPTX
Cache performance considerations
Slideshare
 
PPTX
Recovery & Atom city & Log based Recovery
Meghaj Mallick
 
PDF
8051 serial communication
canh phan
 
PPTX
SQL(DDL & DML)
Sharad Dubey
 
PDF
Difference b/w 8085 & 8086
j4jiet
 
PPTX
Java applet - java
Rubaya Mim
 
PPTX
3.4 deterministic pda
Sampath Kumar S
 
PPS
Ram and-rom-chips
Anuj Modi
 
PPTX
Relational Data Model Introduction
Nishant Munjal
 
PPTX
Unit 4 plsql
DrkhanchanaR
 
PDF
Remote Method Invocation in JAVA
Jalpesh Vasa
 
X86 Architecture
IGZ Software house
 
Runnable interface.34
myrajendra
 
Introduction & history of dbms
sethu pm
 
Create table
Nitesh Singh
 
DDL And DML
pnp @in
 
Xml dtd
HeenaRajput1
 
PHP variables
Siddique Ibrahim
 
dbms lab manual
stalinjothi
 
Cache performance considerations
Slideshare
 
Recovery & Atom city & Log based Recovery
Meghaj Mallick
 
8051 serial communication
canh phan
 
SQL(DDL & DML)
Sharad Dubey
 
Difference b/w 8085 & 8086
j4jiet
 
Java applet - java
Rubaya Mim
 
3.4 deterministic pda
Sampath Kumar S
 
Ram and-rom-chips
Anuj Modi
 
Relational Data Model Introduction
Nishant Munjal
 
Unit 4 plsql
DrkhanchanaR
 
Remote Method Invocation in JAVA
Jalpesh Vasa
 

Similar to Interface result set (20)

PPT
Scrollable Updatable
phanleson
 
PPT
Scrollable Updatable
leminhvuong
 
PDF
java4th.pdf bilgisayar mühendisliği bölümü
Smeyyeztrk10
 
PPTX
Retrieving data from database using result set (1)
rishisingh190
 
PPT
41slideAdvancedDatabaseProgramming.ppt
MohammedNouh7
 
PDF
Java 1-contd
Mukesh Tekwani
 
PPT
Jdbc oracle
yazidds2
 
PPT
JDBC – Java Database Connectivity
Information Technology
 
PPTX
Discuss the scrollable result set in jdbc
manojmanoj218596
 
PPT
4. Database Connectivity using JDBC .ppt
HITENKHEMANI
 
PDF
Java JDBC
Jussi Pohjolainen
 
PPTX
JDBC ResultSet power point presentation by klu
pennywisectsd
 
PPT
KMUTNB - Internet Programming 6/7
phuphax
 
PDF
Overview Of JDBC
Mindfire Solutions
 
PPT
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
PPTX
Session 24 - JDBC, Intro to Enterprise Java
PawanMM
 
PPT
3 database-jdbc(1)
hameedkhan2017
 
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
PPT
statement interface
khush_boo31
 
Scrollable Updatable
phanleson
 
Scrollable Updatable
leminhvuong
 
java4th.pdf bilgisayar mühendisliği bölümü
Smeyyeztrk10
 
Retrieving data from database using result set (1)
rishisingh190
 
41slideAdvancedDatabaseProgramming.ppt
MohammedNouh7
 
Java 1-contd
Mukesh Tekwani
 
Jdbc oracle
yazidds2
 
JDBC – Java Database Connectivity
Information Technology
 
Discuss the scrollable result set in jdbc
manojmanoj218596
 
4. Database Connectivity using JDBC .ppt
HITENKHEMANI
 
JDBC ResultSet power point presentation by klu
pennywisectsd
 
KMUTNB - Internet Programming 6/7
phuphax
 
Overview Of JDBC
Mindfire Solutions
 
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
Session 24 - JDBC, Intro to Enterprise Java
PawanMM
 
3 database-jdbc(1)
hameedkhan2017
 
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
statement interface
khush_boo31
 
Ad

More from myrajendra (20)

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

Recently uploaded (20)

PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 

Interface result set

  • 2. • • • • public interface ResultSetextends Wrapper Throws SQLException { }
  • 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