Chapter 34 Java Database Programming
Chapter 34 Java Database Programming
You may specify a foreign key in the create table statement using the foreign key
clause.
3. A relation can have only one primary key, but may have multiple foreign keys.
4. No.
6. Yes.
7. See
http://www.cs.armstrong.edu/liang/intro6e/supplement/createsampletables_mysql.sql
8.
9.
10.
11.
select distinct firstName, lastName from Student, Enrollment, Course where Student.ssn =
Enrollment.ssn and Course.courseId = Enrollment.courseId
12.
13.
14.
(1) platform independence, i.e., your Java program can run on any platform and access any
relational database. (2) Java has an extensive set of classes and interfaces in the API that you
can use to develop database applications and applets productively and efficiently.
15. A JDBC application loads an appropriate driver using the Driver interface, connects to
the database using the Connection interface, creates and executes SQL statements using
the Statement interface, and processes the result using the ResultSet interface if the
statements return results.
16. Use the Class.for(driverName) method to load the driver with its full name. The driver
class for MySQL, Access, and Oracle are com.mysql.jdbc.Driver,
sun.jdbc.odbc.JdbcOdbcDriver, oracle.jdbc.driver.OracleDriver, respectively.
19. To retrieve values in a ResultSet, use next() to move the cursor to the next row and use
the getXxx(number) or getXxx(columnName) method to retrieve fields from the current
row.
20. JDBC automatically commits a transaction. You can set autoCommit to false using
setAutoCommit(false) on a Connection object.
Or
24. The DatabaseMetaData interface contains the methods for obtaining database-wide
information.
The general information includes the URL, username, product name, product version,
driver name, driver version, available functions, available data types, and so on. The
methods for general information usually return a string, an integer, except that the
method for retrieving available data types returns a ResultSet. Most methods of this type
don't have parameters.
The methods for getting database objects return lists of information in ResultSets. You
can use the normal ResultSet methods, such as getString and getInt, to retrieve data from
these ResultSets. If a given form of metadata is not available, these methods should
throw a SQLException.
25. The ResultSetMetaData interface describes information pertaining to the result set. A
ResultSetMetaData object can be used to find out about the types and properties of the
columns in a ResultSet. The methods in ResultSetMetaData have a single int parameter
representing the column except that the getColumnCount method has no parameters. All
these methods return int, boolean, or String. To create an instance of
ResultSetMetaData, use getResultSetMetaData from an instance of ResultSet.
26. To find the number of columns in a result set, first create an instance of
ResultSetMetaData using the getMetaData() method on a ResultSet. The use
getColumnCount() to return the column count and use getColumnName(int) to return
the column name.