In This Session, You Will Learn To:: Objectives
In This Session, You Will Learn To:: Objectives
Objectives
Answer:
The two layers of JDBC architecture are:
1. JDBC application layer
2. JDBC driver layer
Querying a table:
The SELECT statement is executed using the
executeQuery() method and returns the output in the form
of a ResultSet object.
The code snippet to retrieve data from the Authors table is:
String str = "SELECT * FROM Authors";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(str);
Creating a table:
The CREATE TABLE statement is used to create and define
the structure of a table in a database.
The code snippet to create a table is:
String str="CREATE TABLE Publishers"
+"(pub_id VARCHAR(5),"
+"pub_name VARCHAR(50),"
+"phone INTEGER,"
+"address VARCHAR(50), "
+"city VARCHAR(50), "
+"ZIP VARCHAR(20))";
Statement stmt=con.createStatement();
stmt.execute(str);
Answer:
Driver interface
Method Description
boolean first() Shifts the control of a result set cursor to the
first row of the result set.
boolean isFirst() Determines whether the result set cursor
points to the first row of the result set.
boolean last() Shifts the control of a result set cursor to the
last row of the result set.
boolean isLast() Determines whether the result set cursor
points to the last row of the result set.
Method Description
void insertRow() Inserts a row in the current ResultSet object and
the underlying database table.
void deleteRow() Deletes a row from the current ResultSet object
and the underlying database table.
Which type of result set allows you to move the result set
cursor from first row to last row in forward direction only?
Answer:
Forward only result set
Problem Statement:
Create an application to retrieve information (author id, name,
phone, address, city, state, and zip ) about the authors who are
living in the city where the city name begins with the letter “S”.
Solution:
The application uses Type 4 driver to connect to the library
database on SQL Server and retrieve information abou the
authors who are living in the city where the city name begins
with the letter ‘S’.
You can insert, update, and delete data from a table using the
DML statements in Java applications.
You can create, alter, and drop tables from a database using
the DDL statements in Java applications.
A ResultSet object stores the result retrieved from a database
when a SELECT statement is executed.
You can create various types of ResultSet objects such as
read only, updatable, and forward only.