SlideShare a Scribd company logo
CS3135/CS2135
Object Oriented Programming (Java)
BSCS-3 / MCS-3
Lecture # 18
DB Connectivity
Part-2
Database Connectivity - STEP 3: Query
SQL Queries
• The INSERT INTO statement is used to insert new
records in a table.
• INSERT INTO table_name(field1, field2,field3,…)
VALUES (value1,value2,value3,...);
• The UPDATE statement is used to update existing
records in a table.
• UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
• The DELETE statement is used to delete rows in a
table.
DELETE FROM table_name
WHERE some_column=some_value;
SQL Queries
• The ORDER BY keyword is used to sort the result-set.
• SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name
ASC|DESC;
• Aggregate Functions
• SELECT Avg(fieldname) FROM tablename
• SELECT Count(fieldname) FROM tablename
• SELECT Max(fieldname) FROM tablename
• SELECT Min(fieldname) FROM tablename
• SELECT Sum(fieldname) FROM tablename
Instructor: Tanzila Kehkashan
2
Database Connectivity - Step 4: Process Results
• ResultSet object maintains a cursor pointing to its current row of data.
• ResultSet.FETCH_FORWARD • ResultSet.FETCH_REVERSE
• ResultSet.TYPE_SCROLL_SENSITIVE • ResultSet.TYPE_SCROLL_INSENSITIVE
• ResultSet.CONCUR_UPDATABLE • ResultSet.CONCUR_READ_ONLY
ResulSet object methods Description
boolean absolute(int row) • Moves the cursor to the given row number in this ResultSet object.
void afterLast() • Moves the cursor to the end of this ResultSet object, just after the last row.
void beforeFirst() • Moves the cursor to the front of this ResultSet object, just before the first row.
boolean getBoolean(int) • Retrieves value of column index in current row of this ResultSet object as Boolean.
boolean getBoolean(String) • Retrieves value of column name in current row of this ResultSet object as Boolean.
byte getByte(int)
byte getByte(String)
Date getDate(int)
Date getDate(String)
double getDouble(int)
double getDouble(String)
Instructor: Tanzila Kehkashan
3
Database Connectivity - Step 4: Process Results
ResulSet object methods Description
float getFloat(int)
float getFloat(String)
int getInt(int)
int getInt(String)
long getLong(int)
long getLong(String)
Object getObject(int)
Object getObject(String)
short getShort(int)
short getShort(String)
String getString(int)
String getString(String)
Time getTime(int)
Time getTime(String)
URL getURL(int)
Instructor: Tanzila Kehkashan
4
Database Connectivity - Step 4: Process Results
ResulSet object methods Description
URL getURL(String)
boolean isAfterLast()
boolean isBeforeFirst()
boolean isClosed()
boolean isFirst() Retrieves whether the cursor is on the first row of this ResultSet object.
boolean isLast()
boolean first() Moves the cursor to the first row in this ResultSet object.
boolean last() Moves the cursor to the last row in this ResultSet object.
boolean next() Moves the cursor froward one row from its current position.
boolean previous() Moves the cursor to the previous row in this ResultSet object.
Statement getStatement() Retrieves the Statement object that produced this ResultSet object.
int getRow() Returns current row number
int getFetchDirection()
void setFetchDirection(int) Gives a hint as to direction in which the rows in this ResultSet object will be processed.
void refreshRow() Refreshes the current row with its most recent value in the database.
Instructor: Tanzila Kehkashan
5
Database Connectivity - Step 5: Close
It is a good idea to close the Statement and Connection objects when you have finished with them.
• Close the ResultSet object
• close()
• Close the Statement object
• close()
• Close the connection
• close()
Instructor: Tanzila Kehkashan
6
Instructor: Tanzila Kehkashan
7
Instructor: Tanzila Kehkashan
8

More Related Content

PPTX
Collections in object oriented programming
PDF
The Ring programming language version 1.7 book - Part 39 of 196
PPTX
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
PDF
Sql queries - Basics
PPTX
QTP Automation Testing Tutorial 7
PDF
225523359001djcj4_DBMS_LAB_THEORY_DML.pdf
PDF
The Ring programming language version 1.10 book - Part 45 of 212
Collections in object oriented programming
The Ring programming language version 1.7 book - Part 39 of 196
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
Sql queries - Basics
QTP Automation Testing Tutorial 7
225523359001djcj4_DBMS_LAB_THEORY_DML.pdf
The Ring programming language version 1.10 book - Part 45 of 212

Similar to OOP Lecture 18-DB Connectivity-Part2.pptx (20)

PDF
The Ring programming language version 1.4.1 book - Part 10 of 31
PPT
C1320prespost
PPTX
3 PYTHON INTERACTION WITH SQLITE (concept of python)
PPT
collections
PPTX
C++11 - STL Additions
PDF
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
PPTX
Fundamentals of Database management system Lab Manual.pptx
PPTX
Data structure and algorithm All in One
PDF
Postgres can do THAT?
PDF
How te bring common UI patterns to ADF
PPT
PPT
Ch03_stacks_and_queues.ppt
PPTX
How to Bring Common UI Patterns to ADF
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
PPTX
Structured Query Language(SQL)
PPT
Collections in Java
PPT
Collections
PPTX
Collection implementation classes - Arraylist, linkedlist, Stack
PDF
9 python data structure-2
PPT
Collections
The Ring programming language version 1.4.1 book - Part 10 of 31
C1320prespost
3 PYTHON INTERACTION WITH SQLITE (concept of python)
collections
C++11 - STL Additions
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
Fundamentals of Database management system Lab Manual.pptx
Data structure and algorithm All in One
Postgres can do THAT?
How te bring common UI patterns to ADF
Ch03_stacks_and_queues.ppt
How to Bring Common UI Patterns to ADF
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
Structured Query Language(SQL)
Collections in Java
Collections
Collection implementation classes - Arraylist, linkedlist, Stack
9 python data structure-2
Collections

More from Tanzila Kehkashan (20)

PPTX
OOP Lecture 25-Network Programming-Part2.pptx
PPTX
OOP Lecture 24-Network Programming-Part1.pptx
PPTX
OOP Lecture 23-JAR Files.pptx
PPTX
OOP Lecture 22-JApplet.pptx
PPTX
OOP Lecture 21-Graphics, Audio.pptx
PPTX
OOP Lecture 20-MultiThreading.pptx
PPTX
OOP Lecture 19-JMenuBar.pptx
PPTX
OOP Lecture 17-DB Connectivity-Part1.pptx
PPTX
OOP Lecture 16-Math,Timer.pptx
PPTX
OOP Lecture 15-FileHandling,JFileChooser.pptx
PPTX
OOP Lecture 14-ExceptionHandling.pptx
PPTX
OOP Lecture 13-Color,Font,ImageIcon.pptx
PPTX
OOP Lecture 12-EventHandling2.pptx
PPTX
OOP Lecture 11-EventHandling1.pptx
PPTX
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
PPTX
OOP Lecture 9-JComboBox,JList,JPanel.pptx
PPTX
OOP Lecture 8-JCheckBox,JRadioButton,JProgressBar.pptx
PPTX
OOP Lecture 7-JTextField,JTextArea,JPassword,JButton.pptx
PPTX
OOP Lecture 6-JFrame,JScrollPane,JLabel.pptx
PPTX
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
OOP Lecture 25-Network Programming-Part2.pptx
OOP Lecture 24-Network Programming-Part1.pptx
OOP Lecture 23-JAR Files.pptx
OOP Lecture 22-JApplet.pptx
OOP Lecture 21-Graphics, Audio.pptx
OOP Lecture 20-MultiThreading.pptx
OOP Lecture 19-JMenuBar.pptx
OOP Lecture 17-DB Connectivity-Part1.pptx
OOP Lecture 16-Math,Timer.pptx
OOP Lecture 15-FileHandling,JFileChooser.pptx
OOP Lecture 14-ExceptionHandling.pptx
OOP Lecture 13-Color,Font,ImageIcon.pptx
OOP Lecture 12-EventHandling2.pptx
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
OOP Lecture 9-JComboBox,JList,JPanel.pptx
OOP Lecture 8-JCheckBox,JRadioButton,JProgressBar.pptx
OOP Lecture 7-JTextField,JTextArea,JPassword,JButton.pptx
OOP Lecture 6-JFrame,JScrollPane,JLabel.pptx
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx

Recently uploaded (20)

PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
history of c programming in notes for students .pptx
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Patient Appointment Booking in Odoo with online payment
Salesforce Agentforce AI Implementation.pdf
Computer Software and OS of computer science of grade 11.pptx
history of c programming in notes for students .pptx
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Why Generative AI is the Future of Content, Code & Creativity?
Oracle Fusion HCM Cloud Demo for Beginners
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Complete Guide to Website Development in Malaysia for SMEs
Weekly report ppt - harsh dattuprasad patel.pptx
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Odoo Companies in India – Driving Business Transformation.pdf
Operating system designcfffgfgggggggvggggggggg
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms I-SECS-1021-03
Patient Appointment Booking in Odoo with online payment

OOP Lecture 18-DB Connectivity-Part2.pptx

  • 1. CS3135/CS2135 Object Oriented Programming (Java) BSCS-3 / MCS-3 Lecture # 18 DB Connectivity Part-2
  • 2. Database Connectivity - STEP 3: Query SQL Queries • The INSERT INTO statement is used to insert new records in a table. • INSERT INTO table_name(field1, field2,field3,…) VALUES (value1,value2,value3,...); • The UPDATE statement is used to update existing records in a table. • UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; • The DELETE statement is used to delete rows in a table. DELETE FROM table_name WHERE some_column=some_value; SQL Queries • The ORDER BY keyword is used to sort the result-set. • SELECT column_name,column_name FROM table_name ORDER BY column_name,column_name ASC|DESC; • Aggregate Functions • SELECT Avg(fieldname) FROM tablename • SELECT Count(fieldname) FROM tablename • SELECT Max(fieldname) FROM tablename • SELECT Min(fieldname) FROM tablename • SELECT Sum(fieldname) FROM tablename Instructor: Tanzila Kehkashan 2
  • 3. Database Connectivity - Step 4: Process Results • ResultSet object maintains a cursor pointing to its current row of data. • ResultSet.FETCH_FORWARD • ResultSet.FETCH_REVERSE • ResultSet.TYPE_SCROLL_SENSITIVE • ResultSet.TYPE_SCROLL_INSENSITIVE • ResultSet.CONCUR_UPDATABLE • ResultSet.CONCUR_READ_ONLY ResulSet object methods Description boolean absolute(int row) • Moves the cursor to the given row number in this ResultSet object. void afterLast() • Moves the cursor to the end of this ResultSet object, just after the last row. void beforeFirst() • Moves the cursor to the front of this ResultSet object, just before the first row. boolean getBoolean(int) • Retrieves value of column index in current row of this ResultSet object as Boolean. boolean getBoolean(String) • Retrieves value of column name in current row of this ResultSet object as Boolean. byte getByte(int) byte getByte(String) Date getDate(int) Date getDate(String) double getDouble(int) double getDouble(String) Instructor: Tanzila Kehkashan 3
  • 4. Database Connectivity - Step 4: Process Results ResulSet object methods Description float getFloat(int) float getFloat(String) int getInt(int) int getInt(String) long getLong(int) long getLong(String) Object getObject(int) Object getObject(String) short getShort(int) short getShort(String) String getString(int) String getString(String) Time getTime(int) Time getTime(String) URL getURL(int) Instructor: Tanzila Kehkashan 4
  • 5. Database Connectivity - Step 4: Process Results ResulSet object methods Description URL getURL(String) boolean isAfterLast() boolean isBeforeFirst() boolean isClosed() boolean isFirst() Retrieves whether the cursor is on the first row of this ResultSet object. boolean isLast() boolean first() Moves the cursor to the first row in this ResultSet object. boolean last() Moves the cursor to the last row in this ResultSet object. boolean next() Moves the cursor froward one row from its current position. boolean previous() Moves the cursor to the previous row in this ResultSet object. Statement getStatement() Retrieves the Statement object that produced this ResultSet object. int getRow() Returns current row number int getFetchDirection() void setFetchDirection(int) Gives a hint as to direction in which the rows in this ResultSet object will be processed. void refreshRow() Refreshes the current row with its most recent value in the database. Instructor: Tanzila Kehkashan 5
  • 6. Database Connectivity - Step 5: Close It is a good idea to close the Statement and Connection objects when you have finished with them. • Close the ResultSet object • close() • Close the Statement object • close() • Close the connection • close() Instructor: Tanzila Kehkashan 6