Chapter 4JDBC
Chapter 4JDBC
)
BSc. CSIT 7th Semester
Chapter - 4
4.2. DDL and DML Operations using Java, Prepared Statements, Multiple
Advanced JAVA Programming
Results, Scrollable Result Sets, Updateable Result Sets, Row Sets and Cached
Row Sets, Transactions, SQL Escapes.
12/10/2023
JDBC Architecture
2. Create connection
Chapter – 4 : Database Connectivity (4 Hrs.)
3. Create statement
Advanced JAVA Programming
4. Execute queries
5. Close connection
[Link]
• The base class for exceptions that occur while running JDBC applications is
SQLException.
Advanced JAVA Programming
[Link]
Language.
Usage DDL statements are used to create database, DML statement is used to insert, update
2
schema, constraints, users, tables etc. or delete the records.
Advanced JAVA Programming
Classification DDL has no further classification. DML is further classified into procedural
3
DML and non-procedural DML.
4 Commands CREATE, DROP, RENAME, ALTER. INSERT, SELECT, UPDATE, DELETE.
SELECT
Advanced JAVA Programming
UPDATE
UPDATE ddl
SET DDL_Value = 555 WHERE DDL_Type = 'DML';
DELETE
DELETE FROM DDL
Where id = 2
Connection conn=null;
ResultSet rs = null;
Advanced JAVA Programming
Syntax
Chapter – 4 : Database Connectivity (4 Hrs.)
[Link](SQL);
Syntax:
[Link](1, 55);
[Link](2, 5);
[Link]();
keep the connection open during its life cycle, in which case it is
called connected rowset.
Advanced JAVA Programming
• A row set may also make connection with a database, get data from it, and
then close the connection. Such a row set is called disconnected rowset.
• In JDBC, a row set is represented by the RowSet interface which is defined
in the [Link] package. The [Link] package is an extension of JDBC,
besides the primary package [Link].
queries.
• A JoinRowSet combines data from different RowSet objects, which is
equivalent to SQL JOIN queries.
• A JdbcRowSet is a thin wrapper around a ResultSet that makes it possible
to use the result set as a JavaBeans component.
• A WebRowSet can read and write data in XML format, making it possible to
transfer the data through tiers in a web application.
12/10/2023 [Link]
Er. Jeewan Rai 15
Scrollable ResultSet
• A scrollable ResultSet is one which allows us to retrieve the data in forward
direction as well as backward direction
Chapter – 4 : Database Connectivity (4 Hrs.)
12/10/2023
Er. Jeewan Rai
Example: Scrollable Result Sets
17
Update ResultSet
Update Result Set is used for following operation
•inserting a record,
Chapter – 4 : Database Connectivity (4 Hrs.)
Syntax:
12/10/2023
Er. Jeewan Rai
Example: Update Resultset
19
ResultSet Type Values
• You can create a Statement that returns result sets in one of the following
types:
Chapter – 4 : Database Connectivity (4 Hrs.)
[Link]
- next(): moves the cursor forward one row from its current position.
Chapter – 4 : Database Connectivity (4 Hrs.)
- relative(int rows): moves the cursor a relative number of rows from its
current position. The value of rows can be positive (move forward) or
negative (move backward).
• {keyword 'parameters'}
//Create a Statement object
stmt = [Link]();
Advanced JAVA Programming
escape Keyword
String sql = "SELECT symbol FROM MathSymbols WHERE symbol LIKE '\%' {escape '\'}";
[Link](sql);
Method Description
[Link]("[Link]");
Connection con=[Link]("jdbc:oracle:thin:@localhost:1521:xe","system","o
Advanced JAVA Programming
racle");
[Link](false);
Statement stmt=[Link]();
[Link]("insert into user420 values(190,'abhi',40000");
[Link]("insert into user420 values(191,'umesh',50000");
[Link]();
[Link]
[Link]();
12/10/2023 Er. Jeewan Rai 26
}}
Advanced JAVA Programming
Chapter – 4 : Database Connectivity (4 Hrs.)
12/10/2023
Er. Jeewan Rai
The End
27