O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating the Database

Now that we've got the totals, we're ready to go ahead and save them back to the database. To do that, we'll use the principles we learned earlier in this chapter. First, in Listing 8.20, we'll lay the foundation by connecting to the database and retrieving our information from the Hashtable.

Listing 8.20. ParseOrders.java: Connecting to the Database
0:  import org.xml.sax.helpers.*;
1:  import org.xml.sax.*;
2:  import java.util.*;
3:  import java.sql.*; 4: 5: public class ParseOrders extends DefaultHandler { 6: ... 70: public void showTotals () { 71: 72: Enumeration allProducts = products.keys(); 73: while (allProducts.hasMoreElements()) { 74: String thisKey = (String)allProducts.nextElement(); 75: String thisValue = (String)products.get(thisKey); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required