Java How to Program, 11/e Multiple Choice Test Bank 1 of 6
Chapter 24 Accessing Databases with JDBC
Section 24.1 Introduction
24.1 Q1: Java programs communicate with databases using what API?
a. DBMS.
b. JDBC.
c. RDBMS.
d. Database.
24.1 Q2: Which of the following is a key benefit of using JDBC?
a. It is a simple-to-use database management system.
b. Allows developers to change the underlying database without modifying the Java code.
c. It is a multi-platform database management system.
d. It provides a GUI for database management systems.
Section 24.2 Relational Databases
24.2 Q1: A ________ is a column (or set of columns) which have a unique value that cannot be duplicated
in other rows?
a. primary key.
b. query.
c. SQL statement.
d. lookup value.
24.2 Q2: To obtain data from a table, you ________ the database?
a. select
b. query
c. get
d. None of the above
24.2 Q3: What does a primary key do?
a. Identifies each row of a table.
b. Selects a number of rows from a database.
c. Stores a bunch of related data.
d. None of the above.
Section 24.3 A books Database
24.3 Q1: What is the name of a key in one table that is required to matche a primary key in another table?
a. Foreign key.
b. Matching key.
c. Joined key.
d. Linking key.
24.3 Q2: Which of the following states the Rule of Entity Integrity?
a. Every row must have a value for the primary key and each value must be unique.
b. Every foreign key must appear as another table’s primary key.
Java How to Program, 11/e Multiple Choice Test Bank 2 of 6
c. Every row must have a value for the primary key and values may be repeated.
d. None of the above.
24.3 Q3: What is the relationship between a primary key and its corresponding foreign keys?
a. One-to–one.
b. Many-to-one.
c. Many-to-many.
d. One-to-many.
Section 24.4 SQL
24.4 Q1: Which SQL keyword is used to merge rows from multiple tables?
a. JOIN.
b. INNER JOIN.
c. GROUP.
d. MERGE.
24.4 Q2: Which SQL keyword is required in every query?
a. FROM.
b. WHERE.
c. ORDER BY.
d. LIKE.
Section 24.4.1 Basic SELECT Query
24.4.1 Q1: Which symbol indicates that all columns should be retrieved?
a. ?
b. *
c. +
d. /
24.4.1 Q2: To retrieve specific columns from a table, use _________ to separate the column names.
a. ?
b. *
c. ,
d. –
Section 24.4.2 WHERE Clause
24.4.2 Q1: Selection criteria can be added to a SQL query using which keyword?
a. FROM.
b. WHERE.
c. SELECT.
d. LIKE.
24.4.2 Q2: Pattern matching in a SQL query is performed with which clause?
a. FROM.
b. WHERE.
Java How to Program, 11/e Multiple Choice Test Bank 3 of 6
c. SELECT.
d. LIKE.
Section 24.4.3 ORDER BY Clause
24.4.3 Q1: The result of a query can be sorted by using the optional _________ clause.
a. ORDER BY
b. ORDER
c. SORT BY
d. SORT
24.4.3 Q2: The default sort order in a sorted query is _________.
a. ascending
b. descending
c. natural
d. None of the above
Section 24.4.4 Merging Data from Multiple Tables: INNER JOIN
24.4.4 Q1: When joining tables, the _________ clause specifies the columns from each table that are
compared to determine which rows are merged.
a. ON
b. WHERE
c. LIKE
d. GROUP
24.4.4 Q2: If a query includes columns from multiple tables that have the same name, the statement
must precede those column names with _________.
a. their database names.
b. their database names and a dot.
c. their table names and a dot.
d. their table names.
Section 24.4.5 INSERT Statement
24.4.5 Q1: This keyword is used to add a row to a table.
a. INSERT.
b. ADD.
c. UPDATE.
d. CREATE.
24.4.5 Q2: SQL uses the _________ as a delimiter for strings.
a. double quotes (“ and “)
b. single quotes (‘ and ‘)
c. underscore (–)
d. percent (%)
Java How to Program, 11/e Multiple Choice Test Bank 4 of 6
Section 24.4.6 UPDATE Statement
24.4.6 Q1: In an UPDATE statement, the SET keyword is followed by _________.
a. a comma-separated list of column value-name pairs in the format value = columnName
b. a comma-separated list of column name-value pairs in the format columnName = value
c. a semicolon-separated list of column value-name pairs in the format value = columnName
d. a semicolon-separated list of column name-value pairs in the format columnName = value
Section 24.4.7 DELETE Statement
24.4.7 Q1: Which statement is false?
a. A DELETE statement removes rows from a table.
b. A DELETE statement must specify the table from which to delete.
c. A DELETE statement starts with the keyword DELETE.
d. A WHERE clause must be present in a DELETE statement.
Section 24.5 Setting up a Java DB Database
(No Questions.)
Section 24.5.1 Creating the Chapter’s Databases on Windows
No Questions.
Section 24.5.2 Creating the Chapter’s Databases on macOS
No Questions.
Section 24.5.3 Creating the Chapter’s Databases on Linux
No Questions.
Section 24.6 Connecting to and Querying a Database
(No Questions.)
24.6 Q1: Classes and interfaces for the JDBC API can be found in which package?
a. java.jdbc.
b. javax.jdbc.
c. java.sql.
d. java.sql.jdbc.
24.6 Q2: What exception is thrown if DriverManager method getConnection cannot connect to the
database?
a. DatabaseConnectionException.
b. DatabaseNotFoundException.
c. SQLException.
d. IllegalAccessException.
Section 24.7 Querying the books Database
24.7 Q1: Which constants are used to indicate that a ResultSet is scrollable, insensitive to changes and
read only?
Java How to Program, 11/e Multiple Choice Test Bank 5 of 6
a. TYPE_SCROLLABLE_INSENSITIVE, CONCUR_READ_ONLY.
b. TYPE_SCROLLABLEINSENSITIVE, CONCUR_READONLY.
c. TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY.
d. TYPE_SCROLL_INSENSITIVE, CONCUR_READONLY.
24.7 Q2: Initially, a ResultSet cursor is positioned _________.
a. before the first row
b. at the first row
c. at the last row
Section 24.8 RowSet Interface
24.8 Q1: An implementation of the _________ interface configures the database connection and prepares
query statements automatically.
a. ResultSet
b. RowSet
c. Both of the above
d. Neither of the above
24.8 Q2: Which statement is false?
a. Interface JdbcRowSet is in the javax.rowset package.
b. A CachedRowSet object is scrollable and updatable by default.
c. A JdbcRowSet object is scrollable and updatable by default.
d. JdbcRowSet is a connected RowSet.
Section 24.9 PreparedStatements
24.9 Q1: In a PreparedStatement, parameters are counted from position ________.
a. 0
b. 1
c. 2
d. 3
24.9 Q2: JDBC supports _______, so you do not need to manually load the database driver before
accessing a database.
a. automatic driver downloading
b. automatic driver creation
c. automatic driver discovery
d. None of the above.
24.9 Q3: PreparedStatement method ________ returns a ResultSet.
a. executeUpdate
b. executeQuery
c. execute
d. None of the above.
Java How to Program, 11/e Multiple Choice Test Bank 6 of 6
Section 24.10 Stored Procedures
24.10 Q1: What are individual SQL statements saved in a database called?
a. Stored statements.
b. Stored queries.
c. Stored commands.
d. Stored procedures.
24. 10Q2: SQL statements that are stored in a database can be invoked using an object that implements
interface ________.
a. Callable
b. StoredStatement
c. CallableStatement
d. Connection
Section 24.11 Transaction Processing
24.11 Q1: Transaction processing enables a program to ________ or ________ a transaction based on
whether the transaction was successful.
a. save, delete
b. commit, rollback
c. save, rollback
d. commit, delete
24.11 Q2: Transaction processing enables a program to treat a database operation, or set of operations, as
single operation. This is known as a(n) ________ or a(n) ________.
a. atomic operation, unique operation.
b. unique operation, transaction.
c. atomic operation, transaction.
d. None of the above.