SlideShare une entreprise Scribd logo
1  sur  25
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
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
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

Contenu connexe

Tendances

Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
club23
 

Tendances (20)

Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
C# basics
 C# basics C# basics
C# basics
 
HTML Comprehensive Overview
HTML Comprehensive OverviewHTML Comprehensive Overview
HTML Comprehensive Overview
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Data structures
Data structuresData structures
Data structures
 
String function in my sql
String function in my sqlString function in my sql
String function in my sql
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 

Similaire à Interface result set

13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016
Evan Schultz
 

Similaire à Interface result set (20)

Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Unit ii
Unit iiUnit ii
Unit ii
 
Jpa
JpaJpa
Jpa
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
Cursor & Content Value.pdf
Cursor & Content Value.pdfCursor & Content Value.pdf
Cursor & Content Value.pdf
 
00-review.ppt
00-review.ppt00-review.ppt
00-review.ppt
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Jdbc
JdbcJdbc
Jdbc
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Intro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and ArrayIntro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and Array
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Java
JavaJava
Java
 

Plus de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
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
Earley Information Science
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

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
  • 4.
  • 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
  • 6.
  • 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