Introduction to Java Programming, Includes Data Structures, Eleventh Edition, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Chapter 34 Java Database Programming


Section 34.2 Relational Database Systems
34.1  In a relational data model, _________ defines the representation of the data.
A. Structure
B. Integrity
C. Language
D. SQL

34.2  In a relational data model, _________ imposes constraints on the data.
A. Structure
B. Integrity
C. Language
D. SQL

34.3  In a relational data model, ________ provides the means for accessing and manipulating data.
A. Structure
B. Integrity
C. Language
D. SQL

34.4  _________ specify the permissible values for an attribute.
A. Domain constraints
B. Primary key constraints
C. Foreign key constraints
D. intra-relational constraints
E. inter-relational constraints

34.5  ________ are known as intra-relational constraints, meaning that a constraint involves only one relation.
A. Domain constraints
B. Primary key constraints
C. Foreign key constraints

34.6  ________ is an attribute or a set of attributes that uniquely identifies the relation.
A. A superkey
B. A key
C. A candidate key
D. A primary key

Section 34.3 SQL
34.7  SQL ________ statements may change the contents of a database.
A. SELECT
B. UPDATE
C. DELETE
D. INSERT

34.8  To retrieve all courses with more than 3 credit hours, you write

select * from Course
where numOfCredits > 3;

Is this statement correct?
A. Yes
B. No

Section 34.4 JDBC
34.9  Which of the following statements loads the JDBC-ODBC driver?
A. Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)
B. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
C. Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver)
D. Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")

34.10  Where is com.mysql.jdbc.Driver located?
A. in the standard Java library bundled with JDK
B. in a JAR file mysqljdbc.jar downloadable from the book's Companion Website
C. in a JAR file classes12.jar downloadable from the book's Companion Website
D. in a JAR file ojdbc14.jar downloadable from the book's Companion Website

34.11  Invoking Class.forName method may throw ___________.
A. RuntimeException
B. ClassNotFoundException
C. IOException
D. SQLException

34.12  A database URL for an access database source test is ________.
A. test
B. jdbcodbc:test
C. jdbc:odbc:test
D. sun.jdbc:odbc:test

34.13  A database URL for a MySQL database named test on host panda.armstrong.edu is ________.
A. jdbc.mysql.//panda.armstrong.edu/test
B. jdbc:mysql:/panda.armstrong.edu/test
C. jdbc:mysql://panda.armstrong.edu/test
D. jdbc.mysql://panda.armstrong.edu/test

34.14  To connect to a local MySQL database named test, use
A. Connection connection = DriverManager.getConnection(jdbc:mysql://localhost/test);
B. Connection connection = DriverManager.connect("jdbc:mysql://localhost/test");
C. Connection connection = DriverManager.getConnection("mysql:jdbc://localhost/test");
D. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");

34.15  To create a statement on a Connection object conn, use
A. Statement statement = conn.statement();
B. Statement statement = Connection.createStatement();
C. Statement statement = conn.createStatement();
D. Statement statement = connection.create();

34.16  To execute a SELECT statement "select * from Address" on a Statement object stmt, use
A. stmt.execute("select * from Address");
B. stmt.executeQuery("select * from Address");
C. stmt.executeUpdate("select * from Address");
D. stmt.query("select * from Address");

34.17  Which of the following statements are true?
A. You may load multiple JDBC drivers in a program.
B. You may create multiple connections to a database.
C. You may create multiple statements from one connection.
D. You can send queries and update statements through a Statement object.

34.18  Analyze the following code:

    ResultSet resultSet = statement.executeQuery
      ("select firstName, mi, lastName from Student where lastName "
        + " = 'Smith'");
    System.out.println(resultSet.getString(1));
A. If the SQL SELECT statement returns no result, resultSet is null.
B. The program will have a runtime error, because the cursor in resultSet does not point to a row. You must use resultSet.next() to move the cursor to the first row in the result set. Subsequently, resultSet.next() moves the cursor to the next row in the result set.
C. resultSet.getString(1) returns the firstName field in the result set.
D. resultSet.getString(1) returns the mi field in the result set.

34.19  Suppose that your program accesses MySQL or Oracle database. Which of the following statements are true?
A. If the driver for MySQL and Oracle are not in the classpath, the program will have a syntax error.
B. If the driver for MySQL and Oracle are not in the classpath, the program will have a runtime error, indicating that the driver class cannot be loaded.
C. If the database is not available, the program will have a syntax error.
D. If the database is not available, the program will have a runtime error, when attempting to create a Connection object.

34.20  Which of the following are interfaces?
A. Connection
B. Statement
C. ResultSet
D. DriverManager

34.21  What is the return value from

     stmt.executeUpdate("insert into T values (100, 'Smith')")
A. void
B. an int value indicating how many rows are effected from the invocation
C. a value indicating whether the SQL statement has been executed successfully
D. an object that contains the status of the execution

Section 34.5 PreparedStatement
34.22  Which of the following statements are true?
A. PreparedStatement is a subinterface of Statement
B. PreparedStatement is for SQL query statements only. You cannot create a PreparedStatement for SQL update statements.
C. PreparedStatement is efficient for repeated executions.
D. The parameters in a prepared statement are denoted using the ? sign.

34.23  Suppose a prepared statement is created as follows:

Statement preparedStatement = connection.prepareStatement
  ("insert into Student (firstName, mi, lastName) " +
   "values (?, ?, ?)");

To set a value John to the first parameter, use
A. preparedStatement.setString(0, "John");
B. preparedStatement.setString(1, "John");
C. preparedStatement.setString(0, 'John');
D. preparedStatement.setString(1, 'John');

34.24  If a prepared statement preparedStatement is a SQL SELECT statement, you execute the statement using _________.
A. preparedStatement.execute();
B. preparedStatement.executeUpdate();
C. preparedStatement.executeQuery();
D. preparedStatement.query();

Section 34.6 CallableStatement
34.25  Which of the following statements are true?
A. CallableStatement is a subinterface of PreparedStatement
B. CallableStatement is for SQL query statements only. You cannot create a CallableStatement for SQL update statements.
C. CallableStatement is more efficient than PreparedStatement.
D. CallableStatement is for executing predefined functions and procedures.

34.26  Suppose a callable statement is created as follows:

CallableStatement callableStatement = connection.prepareCall(
  "{call sampleProcedure(?, ?, ?)}");

Assume that the first parameter is an IN parameter with value John. To set this parameter value, use
A. callableStatement.setString(0, "John");
B. callableStatement.setString(1, "John");
C. callableStatement.setString(0, 'John');
D. callableStatement.setString(1, 'John');

34.27  Suppose a callable statement is created as follows:

CallableStatement callableStatement = connection.prepareCall(
  "{call sampleProcedure(?, ?, ?)}");

Assume that the second parameter is an OUT parameter with value John. To register this parameter, use
A. callableStatement.registerOutParameter(0, java.sql.Types.STRING);
B. callableStatement.registerOutParameter(1, java.sql.Types.STRING);
C. callableStatement.registerOutParameter(2, java.sql.Types.STRING);

Section 34.7 Retrieving Metadata
34.28  Database meta data are retrieved through ____________.
A. a Connection object
B. a Statement object
C. a ResultSet Object
D. a PreparedStatement object

34.29  What information may be obtained from a DatabaseMetaData object?
A. database URL and product name
B. JDBC driver name and version
C. maximum number of connections to the database
D. maximum table name length and maximum number of columns in a table

34.30  Result set meta data are retrieved through ____________.
A. a Connection object
B. a Statement object
C. a ResultSet Object
D. a PreparedStatement object

34.31  What information may be obtained from a ResultSetMetaData object?
A. database URL and product name
B. JDBC driver name and version
C. number of columns in the result set
D. number of rows in the result set