SlideShare a Scribd company logo
Retrieving data from
database using ResultSet
Presented by :
Manohar Bhasin, Rishi Singh
CONTENT
 Introduction to Statement and ResultSet Interface
 Retrieving data from database using Statement and
ResultSet Interface.
 Retrieving data from database using
PreparedStatement and ResultSet Interface.
Statement Interface
The object used for executing a static SQL statement
and returning the results it produces.
public interface Statement extends Wrapper,
AutoCloseable
ResultSet Interface
A ResultSet object maintains a cursor pointing to its
current row of data. Initially the cursor is positioned
before the first row.
public interface ResultSet extends Wrapper,
AutoCloseable
Retrieving data from database using Statement
and ResultSet Interface.
String name;
Connection con;
Statement stmt;
ResultSet rs;
…
stmt = con.createStatement();
rs = stmt.executeQuery(“select empname from employee where salary=2000”);
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
stmt.close();
stmt = con.createStatement();
Statement createStatement() throws
SQLException
Creates a Statement object for sending SQL statements to the
database.
Retrieving data from database using Statement
and ResultSet Interface.
String name
Connection con;
Statement stmt;
ResultSet rs;
…
stmt = con.createStatement();
rs = stmt.executeQuery(“select empname from employee where salary=2000”);
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
Stmt.close();
ResultSet executeQuery(String sql) throws SQLException
Executes the given SQL statement, which returns
a ResultSet object.
 rs = stmt.executeQuery(“select empname from employee where
salary=2000”);
stmt = con.createStatement();
Statement createStatement() throws
SQLException
Creates a Statement object for sending SQL statements to the
database.
Retrieving data from database using Statement
and ResultSet Interface.
String name
Connection con;
Statement stmt;
ResultSet rs;
…
stmt = con.createStatement();
rs = stmt.executeQuery(“select empname from employee where salary=2000”);
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
stmt.close();
Retrieving data from database using
PreparedStatement and ResultSet Interface.
String name
Connection con;
PreparedStatement pstmt;
ResultSet rs;
…
pstmt = con.prepareStatement(“select empname from employee where empid= ?” );
Pstmt.setString(1,empid);
rs = pstmt.executeQuery();
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
Stmt.close();
pstmt = con.prepareStatement(“select empname from
employee where empid= ?” );
PreparedStatement prepareStatement(String sql)
throws SQLException
• Creates a PreparedStatement object for sending parameterized
SQL statements to the database.
• This method is optimized for handling parametric SQL
statements that benefit from precompilation.
Retrieving data from database using
PreparedStatement and ResultSet Interface.
String name
Connection con;
PreparedStatement pstmt;
ResultSet rs;
…
pstmt = con.prepareStatement(“select empname from employee where empid= ?” );
Pstmt.setString(1,empid);
rs = pstmt.executeQuery();
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
pstmt.close();
rs = pstmt.executeQuery();
ResultSet executeQuery() throws SQLException
•Executes the SQL query in the PreparedStatement Object and
returns the ResultSet object generated by the query
•Result sets created using the PreparedStatement object will by
default be type TYPE_FORWARD_ONLY and have concurrency
level of CONCUR_READ_ONLY.
Retrieving data from database using
PreparedStatement and ResultSet Interface.
String name
Connection con;
PreparedStatement pstmt;
ResultSet rs;
…
pstmt = con.prepareStatement(“select empname from employee where empid= ?” );
Pstmt.setString(1,empid);
rs = pstmt.executeQuery();
while(rs.next())
{
name=rs.getString(1);
System.out.println(name);
}
rs.close();
pstmt.close();
THANK YOU

More Related Content

What's hot

Js objects
Js objectsJs objects
Js objects
anubavam-techkt
 
Alexander Pavlenko, Senior Java Developer, "Cassandra into"
Alexander Pavlenko, Senior Java Developer, "Cassandra into"Alexander Pavlenko, Senior Java Developer, "Cassandra into"
Alexander Pavlenko, Senior Java Developer, "Cassandra into"
Alina Vilk
 
Cassandra into
Cassandra intoCassandra into
Cassandra into
DataArt
 
Async all around us (promises)
Async all around us (promises)Async all around us (promises)
Async all around us (promises)
Francisco Ferreira
 
Blender-like SceneView Hotkeys Unity extensions
Blender-like SceneView Hotkeys Unity extensionsBlender-like SceneView Hotkeys Unity extensions
Blender-like SceneView Hotkeys Unity extensions
Koji Hasegawa
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
DataminingTools Inc
 
Bootstrap
BootstrapBootstrap
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
Matt Wrock
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Bruce McPherson
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PgDay.Seoul
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
okelloerick
 
Codes
CodesCodes
Codes
Midhun K
 
Json perl example
Json perl exampleJson perl example
Json perl example
Ashoka Vanjare
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
Bruce McPherson
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
Ryosuke Nakamura
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
Kazutaka Tomita
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 bt
Shinichi Ogawa
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
Jan Jongboom
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
Minu Rajasekaran
 

What's hot (20)

Js objects
Js objectsJs objects
Js objects
 
Alexander Pavlenko, Senior Java Developer, "Cassandra into"
Alexander Pavlenko, Senior Java Developer, "Cassandra into"Alexander Pavlenko, Senior Java Developer, "Cassandra into"
Alexander Pavlenko, Senior Java Developer, "Cassandra into"
 
Cassandra into
Cassandra intoCassandra into
Cassandra into
 
Async all around us (promises)
Async all around us (promises)Async all around us (promises)
Async all around us (promises)
 
Blender-like SceneView Hotkeys Unity extensions
Blender-like SceneView Hotkeys Unity extensionsBlender-like SceneView Hotkeys Unity extensions
Blender-like SceneView Hotkeys Unity extensions
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
 
Codes
CodesCodes
Codes
 
Json perl example
Json perl exampleJson perl example
Json perl example
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 bt
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 

Similar to Retrieving data from database using result set (1)

Refactoring Jdbc Programming
Refactoring Jdbc ProgrammingRefactoring Jdbc Programming
Refactoring Jdbc Programming
chanwook Park
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
hameedkhan2017
 
Discuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbcDiscuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbc
manojmanoj218596
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
Information Technology
 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdf
DhirajKumarBiswal
 
Jdbc
JdbcJdbc
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
phanleson
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
Swapnil Kale
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
jitendral
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
leminhvuong
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
phanleson
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
yazidds2
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
Tuan Ngo
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
Mukesh Tekwani
 
Code
CodeCode
Code
mimidas
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
Zianed Hou
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
abhi7692271
 
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVAJDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
AdarshSrungarapu
 

Similar to Retrieving data from database using result set (1) (20)

Refactoring Jdbc Programming
Refactoring Jdbc ProgrammingRefactoring Jdbc Programming
Refactoring Jdbc Programming
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Discuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbcDiscuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbc
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdf
 
Jdbc
JdbcJdbc
Jdbc
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
 
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
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
Code
CodeCode
Code
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Lecture17
Lecture17Lecture17
Lecture17
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVAJDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
 

Recently uploaded

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 

Recently uploaded (20)

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 

Retrieving data from database using result set (1)

  • 1. Retrieving data from database using ResultSet Presented by : Manohar Bhasin, Rishi Singh
  • 2. CONTENT  Introduction to Statement and ResultSet Interface  Retrieving data from database using Statement and ResultSet Interface.  Retrieving data from database using PreparedStatement and ResultSet Interface.
  • 3. Statement Interface The object used for executing a static SQL statement and returning the results it produces. public interface Statement extends Wrapper, AutoCloseable ResultSet Interface A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. public interface ResultSet extends Wrapper, AutoCloseable
  • 4. Retrieving data from database using Statement and ResultSet Interface. String name; Connection con; Statement stmt; ResultSet rs; … stmt = con.createStatement(); rs = stmt.executeQuery(“select empname from employee where salary=2000”); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); stmt.close();
  • 5. stmt = con.createStatement(); Statement createStatement() throws SQLException Creates a Statement object for sending SQL statements to the database.
  • 6. Retrieving data from database using Statement and ResultSet Interface. String name Connection con; Statement stmt; ResultSet rs; … stmt = con.createStatement(); rs = stmt.executeQuery(“select empname from employee where salary=2000”); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); Stmt.close();
  • 7. ResultSet executeQuery(String sql) throws SQLException Executes the given SQL statement, which returns a ResultSet object.  rs = stmt.executeQuery(“select empname from employee where salary=2000”); stmt = con.createStatement(); Statement createStatement() throws SQLException Creates a Statement object for sending SQL statements to the database.
  • 8. Retrieving data from database using Statement and ResultSet Interface. String name Connection con; Statement stmt; ResultSet rs; … stmt = con.createStatement(); rs = stmt.executeQuery(“select empname from employee where salary=2000”); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); stmt.close();
  • 9. Retrieving data from database using PreparedStatement and ResultSet Interface. String name Connection con; PreparedStatement pstmt; ResultSet rs; … pstmt = con.prepareStatement(“select empname from employee where empid= ?” ); Pstmt.setString(1,empid); rs = pstmt.executeQuery(); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); Stmt.close();
  • 10. pstmt = con.prepareStatement(“select empname from employee where empid= ?” ); PreparedStatement prepareStatement(String sql) throws SQLException • Creates a PreparedStatement object for sending parameterized SQL statements to the database. • This method is optimized for handling parametric SQL statements that benefit from precompilation.
  • 11. Retrieving data from database using PreparedStatement and ResultSet Interface. String name Connection con; PreparedStatement pstmt; ResultSet rs; … pstmt = con.prepareStatement(“select empname from employee where empid= ?” ); Pstmt.setString(1,empid); rs = pstmt.executeQuery(); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); pstmt.close();
  • 12. rs = pstmt.executeQuery(); ResultSet executeQuery() throws SQLException •Executes the SQL query in the PreparedStatement Object and returns the ResultSet object generated by the query •Result sets created using the PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have concurrency level of CONCUR_READ_ONLY.
  • 13. Retrieving data from database using PreparedStatement and ResultSet Interface. String name Connection con; PreparedStatement pstmt; ResultSet rs; … pstmt = con.prepareStatement(“select empname from employee where empid= ?” ); Pstmt.setString(1,empid); rs = pstmt.executeQuery(); while(rs.next()) { name=rs.getString(1); System.out.println(name); } rs.close(); pstmt.close();