Monday, 9 March 2009

Java™ How to Program, Sixth Edition - Part25

Few weeks back i started reading Java™ How to Program, Sixth Edition By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

Nice book written By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

I wanted to share few quotations found the book from the 25th chapter.

1) A database is an integrated collection of data. A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data for many users.

2) Today's most popular database management systems are relational database systems.

3) SQL is the international standard language used almost universally with relational database systems to perform queries and manipulate data.

4) Programs connect to, and interact with, relational databases via an interfacesoftware that facilitates communications between a database management system and a program.

5) Java programmers communicate with databases and manipulate their data using the JDBC API. A JDBC driver enables Java applications to connect to a database in a particular DBMS and allows programmers to retrieve and manipulate database data.

6) A relational database stores data in tables. Tables are composed of rows and rows are composed of columns in which values are stored.

7) A primary key provides a unique value that cannot be duplicated in other rows of the same table.

8) Each column of a table represents a different attribute.

9) The primary key can be composed of more than one column.

10) SQL provides a rich set of language constructs that enable programmers to define complex queries to retrieve data from a database.

11) Every column in a primary key must have a value, and the value of the primary key must be unique. This is known as the Rule of Entity Integrity.

12) A one-to-many relationship between tables indicates that a row in one table can have many related rows in a separate table.

13) A foreign key is a column in a table that matches the primary key column in another table.

14) The foreign key helps maintain the Rule of Referential Integrity: Every foreign key value must appear as another table's primary key value. Foreign keys enable information from multiple tables to be joined together. There is a one-to-many relationship between a primary key and its corresponding foreign key.

15) The basic form of a query is


SELECT * FROM tableName


where the asterisk (*) indicates that all columns from tableName should be selected, and tableName specifies the table in the database from which rows will be retrieved.

16) To retrieve specific columns from a table, replace the asterisk (*) with a comma-separated list of column names.

Programmers process query results by knowing in advance the order of the columns in the result. Specifying columns explicitly guarantees that they are always returned in the specified order, even if the actual order in the table(s) is different.

The optional WHERE clause in a query specifies the selection criteria for the query. The basic form of a query with selection criteria is


SELECT columnName1, columnName2, ... FROM tableName WHERE criteria


17) The WHERE clause can contain operators <, >, <=, >=, =, <> and LIKE. Operator LIKE is used for string pattern matching with wildcard characters percent (%) and underscore (_).

18) A percent character (%) in a pattern indicates that a string matching the pattern can have zero or more characters at the percent character's location in the pattern.

19) An underscore (_) in the pattern string indicates a single character at that position in the pattern.

20) The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of an ORDER BY clause is


SELECT columnName1, columnName2, ... FROM tableName ORDER BY column ASC
SELECT columnName1, columnName2, ... FROM tableName ORDER BY column DESC


where ASC specifies ascending order, DESC specifies descending order and column specifies the column on which the sort is based. The default sorting order is ascending, so ASC is optional.

21) Multiple columns can be used for ordering purposes with an ORDER BY clause of the form


ORDER BY column1 sortingOrder, column2 sortingOrder, ...


The WHERE and ORDER BY clauses can be combined in one query. If used, ORDER BY must be the last clause in the query.

22) An INNER JOIN merges rows from two tables by matching values in columns that are common to the tables. The basic form for the INNER JOIN operator is:


SELECT columnName1, columnName2,...
FROM table1
INNER JOIN table2
ON table1.columnName = table2.columnName


23) The ON clause specifies the columns from each table that are compared to determine which rows are joined. If a SQL statement uses columns with the same name from multiple tables, the column names must be fully qualified by prefixing them with their table names and a dot (.).

24) An INSERT statement inserts a new row into a table. The basic form of this statement is


INSERT INTO tableName ( columnName1, columnName2, ..., columnNameN )
VALUES ( value1, value2, ..., valueN )


where tableName is the table in which to insert the row. The tableName is followed by a comma-separated list of column names in parentheses. The list of column names is followed by the SQL keyword VALUES and a comma-separated list of values in parentheses.

25) SQL uses single quotes (') as the delimiter for strings. To specify a string containing a single quote in SQL, the single quote must be escaped with another single quote.

26) An UPDATE statement modifies data in a table. The basic form of an UPDATE statement is


UPDATE tableName
SET columnName1 = value1, columnName2 = value2, ..., columnNameN = valueN
WHERE criteria


where tableName is the table in which to update data. The tableName is followed by keyword SET and a comma-separated list of column name/value pairs in the format columnName = value. The optional WHERE clause criteria determines which rows to update.

27) A DELETE statement removes rows from a table. The simplest form for a DELETE statement is


DELETE FROM tableName WHERE criteria


where tableName is the table from which to delete a row (or rows). The optional WHERE criteria determines which rows to delete.

28) Package java.sql contains classes and interfaces for accessing relational databases in Java.

29) A program must load a JDBC driver class before the program can connect to a database.

30) JDBC supports four categories of drivers: JDBC-to-ODBC bridge driver (Type 1), Native-API, partly Java driver (Type 2), Pure Java client to server driver (Type 3) and Pure Java driver (Type 4).

31) An object that implements interface Connection manages the Connection between a Java program and a database. Connection objects enable programs to create SQL statements that access data.

32) Method getConnection of class DriverManager attempts to connect to a database specified by its URL argument. The URL helps the program locate the database. The URL includes the protocol for communication, the subprotocol for communication and the name of the database.

33) Connection method createStatement creates an object of type Statement. The program uses the Statement object to submit SQL statements to the database.

34) Statement method executeQuery executes a query and returns an object that implements interface ResultSet containing the query result. ResultSet methods enable a program to manipulate query results.

35) A ResultSetMetaData object describes a ResultSet's contents. Programs can use metadata programmatically to obtain information about the ResultSet column names and types.

36) ResultSetMetaData method getColumnCount retrieves the number of ResultSet columns.

37) ResultSet method next positions the ResultSet cursor to the next row in the ResultSet. The cursor points to the current row. Method next returns boolean value TRue if it is able to position to the next row; otherwise, the method returns false. This method must be called to begin processing a ResultSet.

38) When processing ResultSets, it is possible to extract each column of the ResultSet as a specific Java type. ResultSetMetaData method getColumnType returns a constant integer from class Types (package java.sql) indicating the type of the data for a specific column.

39) ResultSet get methods typically receive as an argument either a column number (as an int) or a column name (as a String) indicating which column's value to obtain.

40) ResultSet row and column numbers start at 1.

41) Each Statement object can open only one ResultSet object at a time. When a Statement returns a new ResultSet, the Statement closes the prior ResultSet.

42) Connection method createStatement has an overloaded version that takes two arguments: the result type and the result concurrency. The result type specifies whether the ResultSet's cursor is able to scroll in both directions or forward only and whether the ResultSet is sensitive to changes. The result concurrency specifies whether the ResultSet can be updated with ResultSet's update methods.

43) Some JDBC drivers do not support scrollable or updatable ResultSets.

44) TableModel method getColumnClass returns a Class object that represents the superclass of all objects in a particular column. JTable uses this information to set up the default cell renderer and cell editor for that column in a JTable.

45) ResultSetMetaData method getColumnClassName obtains the fully qualified class name of the specified column.

46) TableModel method getColumnCount returns the number of columns in the model's underlying ResultSet.

47) TableModel method getColumnName returns the name of the column in the model's underlying ResultSet.

48) ResultSetMetaData method getColumnName obtains the column name from the ResultSet.

49) TableModel method getrowCount returns the number of rows in the model's underlying ResultSet.

50) TableModel method getValueAt returns the Object at a particular row and column of the model's underlying ResultSet.

51) ResultSet method absolute positions the ResultSet cursor at a specific row.

52) AbstractTableModel method fireTableStructureChanged notifies any JTable using a particular TableModel object as its model that the data in the model has changed.

53) JDBC enables programs to invoke stored procedures using objects that implement interface CallableStatement.

54) CallableStatement can specify input parameters, like PreparedStatement. In addition, CallableStatement can specify output parameters in which a stored procedure can place return values.

55) Interface RowSet configures the database connection and executes the query automatically.

56) There are two types of RowSetsconnected and disconnected.

57) A connected RowSet connects to the database once and remains connected until the application terminates.

58) A disconnected RowSet connects to the database, executes a query to retrieve the data from the database and then closes the connection.

59) JdbcRowSet, a connected RowSet, acts as a wrapper for a ResultSet object, and allows programmers to scroll and update the rows in the ResultSet. Unlike a ResultSet object, a JdbcRowSet object is scrollable and updatable by default.

60) CachedRowSet, a disconnected RowSet, caches the data of a ResultSet in memory. Like JdbcRowSet, a CachedRowSet object is scrollable and updatable. A CachedRowSet object is also serializable, so it can be passed between Java applications through a network, such as the Internet.

About the Authors

Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.

Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of the MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered Java, C, C++, Internet and World Wide Web courses to industry clients, including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, Compaq, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, Open Environment Corporation, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the most experienced Java corporate trainers having taught about 100 professional Java training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.

No comments: