[ Team LiB ] 6.1 A Quick Introduction
[ Team LiB ] 6.1 A Quick Introduction to Databases Because any large collection of information is in a sense a database, there are many kinds of databases. The most commonly used kinds of commercial databases are called relational databases. Relational databases store information in conceptually simple structures called tables. A table in a database is something like an HTML table or, for that matter, a table in blog. For example, Table 6.1 contains some information about a CD collection. Table 6.1. A Table with CD Information Artist Album Name Black Tape for a Blue Girl The Scavenger Bride Mors Syphylitica Feather and Fate Voltaire Boo Hoo The data in Table 6.1 is organized into rows, each of which describes a single CD. Each row has columns, or fields, each containing a simple attribute of the CD. Each column also has a name, specified in the table header. A table in a database also has rows containing named columns; the only additional feature is that each column also has a specified type. Most databases handle types that will be familiar to Java developers: integers, characters, strings, dates, floats, and so on. Some fields will be allowed to have a special value, NULL, which means “no data is available.” The empty test as used in Listing 4.12 can be used to check for this special value. Next, consider the problem of adding track data to the CD table. One possibility would be simply to add fields, such as track title and track length, to Table 6.1, but doing so would mean that every track entry would need to contain the album and artist name as well, which would waste space on the page or on disc, in the case of a real database. It would be much more efficient to use two tables: one for tracks and one for CDs. The two can be linked by giving each CD a unique integer ID and referencing that ID in the track table. This would lead to Tables 6.2 and 6.3. Using integers to link up tables is a very common technique, especially when mapping one-to-many relationships, whereby a row in one table may connect to many rows of another table. Integers are small and so do not take up much space in the database, and because integers are easy to sort and manipulate, looking up information based on an ID is typically very fast. Similarly, because artists typically have many albums, another possible efficiency is to be gained by moving artists into their own tables and using an artist ID to map them to their albums. Many, many databases are available. Many business sites use products from Oracle or Microsoft, but a number of high-quality, free databases also are available. These databases are perfectly suitable for small to midsized sites or for development and are very attractive to people who cannot afford a large commercial database. MySQL and PostgreSQL are prime examples of this latter type of database. MySQL is available from http://www.mysql.org, and PostgreSQL is available from http://www.postgresql.org. Table 6.2. The CD Table with a Unique ID Artist Album Name Album ID Black Tape for a Blue Girl The Scavenger Bride 1 Page 108
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services