• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Server-Side Processing

Many options are available for server-side processing, but we will explore several approaches using basic Java servlets. We will first illustrate a simple HTML query result using JDBC in our servlet to connect to a MySQL database. Recall from Chapter 22, “SVG and PHP: Building an Online Survey,” that MySQL was used with PHP and Perl, but here we connect using the Java JDBC API. We will then enhance our query result with an alternative SVG bar chart display. Because we can choose from several methods of handling XML, we will illustrate four common ways of customizing the SVG chart template with the results of our database query.

Servlet 1: Database Access—Query Database and Return HTML Table

First, we need to set up a database on the server. Any SQL database will do, but our project uses MySQL as a freely available example (http://www.mysql.org/). Again, this population data was taken from the U.S. Census Bureau Web site. Census population figures are available for several levels of detail: city, county, tract, block group, and block in progressively finer grain. For this case study, we've chosen to use the tract-level polygons. Numerous additional population figures are available, including age, income, race, and gender. In this example, we pulled a limited subset of age and gender. There are more than 100 population categories to choose from, but we will arbitrarily limit the example to just 12 categories. First, we create a simple flat table in our MySQL database on the server with two Integer fields per record plus a primary key id field. Listing 25.5 shows the SQL CREATE TABLE command to set up this table.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint