Introduction to Java Programming, Sixth Edition, Y. Daniel Liang
Chapter 32 Java Database Programming
Section 32.2 Relational Database Systems
1
In a relational data model, _________ defines the representation of the data.
A.
Structure
B.
Integrity
C.
Language
D.
SQL
2
In a relational data model, _________ imposes constraints on the data.
A.
Structure
B.
Integrity
C.
Language
D.
SQL
3
In a relational data model, ________ provides the means for accessing and manipulating data.
A.
Structure
B.
Integrity
C.
Language
D.
SQL
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
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
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
7
SQL ________ statements may change the contents of a database.
A.
SELECT
B.
UPDATE
C.
DELETE
D.
INSERT
Section 32.4 JDBC
8
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")
9
Where is com.mysql.jdbc.Driver located?
A.
in the standard Java library bundled with JDK
B.
in a JAR file mysqljdbc.jar
C.
in a JAR file classes12.jar
10
Invoking Class.forName method may throw ___________.
A.
RuntimeException
B.
ClassNotFoundException
C.
IOException
D.
SQLException
11
A database URL for an access database source test is ________.
A.
test
B.
jdbcodbc:test
C.
jdbc:odbc:test
D.
sun.jdbc:odbc:test
12
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
13
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");
14
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();
15
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");
16
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.
17
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.
18
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.
19
Which of the following are interfaces?
A.
Connection
B.
Statement
C.
ResultSet
D.
DriverManager
20
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 32.5 PreparedStatement
21
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 is denoted using the ? sign.
Section 32.6 Retrieving Metadata
22
Database meta data are retrieved through ____________.
A.
a Connection object
B.
a Statement object
C.
a ResultSet Object
D.
a PreparedStatement object
23
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
24
Result set meta data are retrieved through ____________.
A.
a Connection object
B.
a Statement object
C.
a ResultSet Object
D.
a PreparedStatement object
25
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