You are on page 1of 2

Lecture Assignment

Tutorial Week 8
Our readings (lecture notes and video lecture) this week discuss the JDBC (Java Database
connectivity). Write the answers for all questions in the table according to your understanding.
PLEASE USE YOUR OWN WORDS. DO NOT COPY FROM THE WEB.

Questions Answers
1. What are the advantages of developing database The advantages of developing
applications using Java? database applications using Java is
Platform independence Java
program will run on any platform
and access any relational database.

2. Describe the following JDBC interfaces: Driver, Driver is to load JDBC drivers
Connection, Statement, and ResultSet. Connection establishing connection
to the database
Statement preparing and executing
an SQL statement
ResultSet is for the output
3. Write a code fragment to load a JDBC driver. Class.forName(“JDBCDriverClass”);
4. Create a connection object using Connection connection =
DriverManager.getConnection() method. DriverManager.getConnection();
5. Describe the differences between execute, Execute method should be used if
executeQuery, and executeUpdate. the execution produces
multiple result sets, multiple update
counts, or a
combination of result sets and
update count.

ExecuteQuery method should be


used if the execution
produces a single result set, such
as SQL statement.

ExecuteUpdate method should be


used if the statement
results in a single update count or

MMR2020@FSKM
Lecture Assignment

no update count, such as


SQL INSRT, DELETE, UPDATE, or
DDL statement.
6. Given SQL statement in the following code. Statement statement =
connection.createStatement();
String SQL = "Update Employees SET age = ?
WHERE id = ?"; Statement pstmt =
connection.prepareStatement(SQL);
- Create a Statement Object
- Create a PreparedStatement Object

MMR2020@FSKM

You might also like