Chapter 7. Adding database support

Table of Contents

1. The datasource participant
1.1. Datasource parameters
1.1.1. Username and password
1.1.2. Database driver
1.1.3. URL
1.1.4. Connection pool
2. Selecting a data source
3. The Friend bean
4. Managing the data
4.1. Using the right data source
5. Displaying the friends
5.1. Displaying one friend at a time
5.2. Writing a row processor
6. Adding friends
6.1. Declaring the new element
6.2. Submission beans
6.3. The add template
6.4. Adding a friend to the database
7. Finishing up the example
7.1. Installing and removing the database table
7.2. Creating the table
7.3. Cleaning up
8. We're done!

So far, our Friends list is quite limited, since we don't have a place to store the list of friends yet. The last missing part is the database support, which we will add in this chapter. We assume that you are already somewhat familiar with SQL databases and in particular the Java framework for handling databases, JDBC.

Often when developing and deploying web applications, there's a need to handle some kind of dynamic data, like the list of friends in our example. Other examples might be news entries, articles, images, or why not all the contents of a web site? If a database is used as storage, it's easy to design very powerful and extensible applications that are easier to maintain than if the data would be scattered around in various files.

We'll show that incorporating a database into the design is a straightforward and easy task with RIFE.