SlideShare a Scribd company logo
1 of 11
DISCUSSTHE SCROLLABLE RESULT
SET IN JDBC
MOTAPALUKULA MANOJ
20951A0585
Scrollable Result Set
Normal Result Set allows fetching elements in forward only direction. However,
Scrollable Result Set allows us to easily move in forward/backward direction.
To create scrollable Result Set, we must use a Statement/PreparedStatement object
and provide scroll type to create Statement/prepare Statement method.
Syntax :
PreparedStatement pstmt = conn.prepareStatement (sql, Scroll type
constant, Concurrency constant);
Statement stmt = conn.createStatement(Scroll type
constant,Concurrency constant);
Scroll type constant
There are 3 scroll type constants can be used with ResultSets.
ResultSet.TYPE_FORWARD_ONLY
Default type.. only allows forward only fetching
ResultSet.TYPE_SCROLL_INSENSITIVE
Allows both forward and backward movement. Not sensitive to ResultSet updates.
ResultSet.TYPE_SCROLL_SENSITIVE
Allows both forward and backward movement. Not sensitive to ResultSet updates.
Concurrency constant
We can use following Concurrency constants for the ResultSets.
ResultSet.CONCUR_READ_ONLY
Default value .. ResultSet can not be updated.
ResultSet.CONCUR_UPDATABLE
Signifies an updatable ResultSet.
Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENS
ITIVE, ResultSet.CONCUR_UPDATABLE);
PreparedStatement pstmt =
conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
Example program for Scrollable
ResultSet
We have created an Employee table in local MySQL database.
In this example, we will traverse through the data retrieved from Employee table using
Scrollable ResultSet.
package com.topjavatutorial.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ScrollableResultsetDemo {
public static void main(String[] args) throws SQLException
{ String url ="jdbc:mysql://localhost:3306/TestDB";
String user = "userid";//add your db user id here
String password = "password";//add your db password here
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("Successfully connected");
getEmployeeData(conn); }
private static void getEmployeeData(Connection conn) throws SQLException{
String sql = "select id,name,age from employee";
try(PreparedStatement pstmt =
conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);){ ResultSet rs = pstmt.executeQuery();
System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " +
rs.getInt("age"));
//Last Record
rs.last();
System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " +
rs.getInt("age"));
//Previous Record
rs.previous();
System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " +
rs.getInt("age"));
//Next Record
rs.next();
System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " +
rs.getInt("age"));
} } }
Output
Successfully connected
Emp Id : 8, Name : John Doe, Age : 21
Emp Id : 13, Name : James, Age : 31
Emp Id : 12, Name : James, Age : 23
Emp Id : 13, Name : James, Age : 31
Discuss the scrollable result set in jdbc

More Related Content

What's hot

Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithmnehrurevathy
ย 
Java Platform Security Architecture
Java Platform Security ArchitectureJava Platform Security Architecture
Java Platform Security ArchitectureRamesh Nagappan
ย 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)shalinikarunakaran1
ย 
Parallel projection
Parallel projectionParallel projection
Parallel projectionPrince Shahu
ย 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive SachiniGunawardana
ย 
Footprinting and reconnaissance
Footprinting and reconnaissanceFootprinting and reconnaissance
Footprinting and reconnaissanceNishaYadav177
ย 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curveArvind Kumar
ย 
Active directory
Active directory Active directory
Active directory deshvikas
ย 
IP Security
IP SecurityIP Security
IP SecurityKeshab Nath
ย 
Module 8 System Hacking
Module 8   System HackingModule 8   System Hacking
Module 8 System Hackingleminhvuong
ย 
Email server configuration on cisco packet tracer
Email server configuration on cisco packet tracerEmail server configuration on cisco packet tracer
Email server configuration on cisco packet tracerArjun Das
ย 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linuxSreenatha Reddy K R
ย 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithmMani Kanth
ย 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
ย 
3 d viewing
3 d viewing3 d viewing
3 d viewingDeepak Singh
ย 
Cricket predictor
Cricket predictorCricket predictor
Cricket predictorRajat Mittal
ย 
Security Attacks.ppt
Security Attacks.pptSecurity Attacks.ppt
Security Attacks.pptZaheer720515
ย 

What's hot (20)

Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
ย 
Java Platform Security Architecture
Java Platform Security ArchitectureJava Platform Security Architecture
Java Platform Security Architecture
ย 
Dns
DnsDns
Dns
ย 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
ย 
Parallel projection
Parallel projectionParallel projection
Parallel projection
ย 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive
ย 
Footprinting and reconnaissance
Footprinting and reconnaissanceFootprinting and reconnaissance
Footprinting and reconnaissance
ย 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
ย 
Active directory
Active directory Active directory
Active directory
ย 
IP Security
IP SecurityIP Security
IP Security
ย 
Mcse 2012
Mcse 2012Mcse 2012
Mcse 2012
ย 
Module 8 System Hacking
Module 8   System HackingModule 8   System Hacking
Module 8 System Hacking
ย 
Email server configuration on cisco packet tracer
Email server configuration on cisco packet tracerEmail server configuration on cisco packet tracer
Email server configuration on cisco packet tracer
ย 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linux
ย 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
ย 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
ย 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
ย 
3 d viewing
3 d viewing3 d viewing
3 d viewing
ย 
Cricket predictor
Cricket predictorCricket predictor
Cricket predictor
ย 
Security Attacks.ppt
Security Attacks.pptSecurity Attacks.ppt
Security Attacks.ppt
ย 

Similar to Discuss the scrollable result set in jdbc

KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7phuphax
ย 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.pptSwapnil Kale
ย 
JDBC โ€“ Java Database Connectivity
JDBC โ€“ Java Database ConnectivityJDBC โ€“ Java Database Connectivity
JDBC โ€“ Java Database ConnectivityInformation Technology
ย 
Retrieving data from database using result set (1)
Retrieving data from database using result set (1)Retrieving data from database using result set (1)
Retrieving data from database using result set (1)rishisingh190
ย 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Databasejitendral
ย 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
ย 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
ย 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
ย 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
ย 
Scrollable Test App
Scrollable Test AppScrollable Test App
Scrollable Test AppPeeyush Ranjan
ย 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBCBG Java EE Course
ย 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdfDhirajKumarBiswal
ย 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorialDharma Kshetri
ย 
Module 5 jdbc.ppt
Module 5   jdbc.pptModule 5   jdbc.ppt
Module 5 jdbc.pptMrsRLakshmiIT
ย 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
ย 

Similar to Discuss the scrollable result set in jdbc (20)

Jdbc
JdbcJdbc
Jdbc
ย 
KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7
ย 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
ย 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
ย 
JDBC โ€“ Java Database Connectivity
JDBC โ€“ Java Database ConnectivityJDBC โ€“ Java Database Connectivity
JDBC โ€“ Java Database Connectivity
ย 
Retrieving data from database using result set (1)
Retrieving data from database using result set (1)Retrieving data from database using result set (1)
Retrieving data from database using result set (1)
ย 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
ย 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
ย 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
ย 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
ย 
Jdbc
JdbcJdbc
Jdbc
ย 
Java JDBC
Java JDBCJava JDBC
Java JDBC
ย 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
ย 
Scrollable Test App
Scrollable Test AppScrollable Test App
Scrollable Test App
ย 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
ย 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdf
ย 
Jdbc
JdbcJdbc
Jdbc
ย 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
ย 
Module 5 jdbc.ppt
Module 5   jdbc.pptModule 5   jdbc.ppt
Module 5 jdbc.ppt
ย 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
ย 

Recently uploaded

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
ย 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
ย 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
ย 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
ย 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
ย 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
ย 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
ย 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
ย 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Call Girls in Nagpur High Profile
ย 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
ย 

Recently uploaded (20)

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
ย 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
ย 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
ย 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ย 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
ย 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
ย 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
ย 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
ย 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
ย 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
ย 

Discuss the scrollable result set in jdbc

  • 1. DISCUSSTHE SCROLLABLE RESULT SET IN JDBC MOTAPALUKULA MANOJ 20951A0585
  • 2. Scrollable Result Set Normal Result Set allows fetching elements in forward only direction. However, Scrollable Result Set allows us to easily move in forward/backward direction. To create scrollable Result Set, we must use a Statement/PreparedStatement object and provide scroll type to create Statement/prepare Statement method. Syntax : PreparedStatement pstmt = conn.prepareStatement (sql, Scroll type constant, Concurrency constant); Statement stmt = conn.createStatement(Scroll type constant,Concurrency constant);
  • 3. Scroll type constant There are 3 scroll type constants can be used with ResultSets. ResultSet.TYPE_FORWARD_ONLY Default type.. only allows forward only fetching ResultSet.TYPE_SCROLL_INSENSITIVE Allows both forward and backward movement. Not sensitive to ResultSet updates. ResultSet.TYPE_SCROLL_SENSITIVE Allows both forward and backward movement. Not sensitive to ResultSet updates.
  • 4. Concurrency constant We can use following Concurrency constants for the ResultSets. ResultSet.CONCUR_READ_ONLY Default value .. ResultSet can not be updated. ResultSet.CONCUR_UPDATABLE Signifies an updatable ResultSet.
  • 5. Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENS ITIVE, ResultSet.CONCUR_UPDATABLE); PreparedStatement pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  • 6. Example program for Scrollable ResultSet We have created an Employee table in local MySQL database. In this example, we will traverse through the data retrieved from Employee table using Scrollable ResultSet.
  • 7. package com.topjavatutorial.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class ScrollableResultsetDemo { public static void main(String[] args) throws SQLException { String url ="jdbc:mysql://localhost:3306/TestDB";
  • 8. String user = "userid";//add your db user id here String password = "password";//add your db password here Connection conn = DriverManager.getConnection(url, user, password); System.out.println("Successfully connected"); getEmployeeData(conn); } private static void getEmployeeData(Connection conn) throws SQLException{ String sql = "select id,name,age from employee"; try(PreparedStatement pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);){ ResultSet rs = pstmt.executeQuery();
  • 9. System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " + rs.getInt("age")); //Last Record rs.last(); System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " + rs.getInt("age")); //Previous Record rs.previous(); System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " + rs.getInt("age")); //Next Record rs.next(); System.out.println("Emp Id : " + rs.getInt("id") + ", Name : " + rs.getString("name") + ", Age : " + rs.getInt("age")); } } }
  • 10. Output Successfully connected Emp Id : 8, Name : John Doe, Age : 21 Emp Id : 13, Name : James, Age : 31 Emp Id : 12, Name : James, Age : 23 Emp Id : 13, Name : James, Age : 31