This example has three parts:
// Create a server object. AS400 mySystem = new AS400 ("mySystem.myComp.com", "UserId", "Password"); // Register and get a connection to the database. DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver()); Connection connection = DriverManager.getConnection("jdbc:as400://" + mySystem.getSystemName()); // Execute an SQL statement and get the result set. Statement statement = connection.createStatement(); statement.execute("select * from qiws.qcustcdt"); ResultSet resultSet = statement.getResultSet(); // Create the SQLResultSetRowData object and initialize to the result set. SQLResultSetRowData rowData = new SQLResultSetRowData(resultSet); // Create an HTML table object to be used by the converter. HTMLTable table = new HTMLTable(); // Set descriptive column headers. String[] headers = {"Customer Number", "Last Name", "Initials", "Street Address", "City", "State", "Zip Code", "Credit Limit", "Charge Code", "Balance Due", "Credit Due"}; table.setHeader(headers); // Set several formatting options within the table. table.setBorderWidth(2); table.setCellSpacing(1); table.setCellPadding(1); // Create an HTML converter object and convert the rowData to HTML. HTMLTableConverter conv = new HTMLTableConverter(); conv.setTable(table); HTMLTable[] html = conv.convertToTables(rowData); // Display the HTML table generated by the converter. System.out.println(html[0]);HTML source generated from the Java source by the using HTMLTableConverter
Using the HTMLTableConverter class in the Java source example above generates the following HTML code.
<table border="2" cellpadding="1" cellspacing="1"> <tr> <th>Customer Number</th> <th>Last Name</th> <th>Initials</th> <th>Street Address</th> <th>City</th> <th>State</th> <th>Zip Code</th> <th>Credit Limit</th> <th>Charge Code</th> <th>Balance Due</th> <th>Credit Due</th> </tr> <tr> <td>938472</td> <td>Henning </td> <td>G K</td> <td>4859 Elm Ave </td> <td>Dallas</td> <td>TX</td> <td align="right">75217</td> <td align="right">5000</td> <td align="right">3</td> <td align="right">37.00</td> <td align="right">0.00</td> </tr> <tr> <td>839283</td> <td>Jones </td> <td >B D</td> <td>21B NW 135 St</td> <td>Clay </td> <td>NY</td> <td align="right">13041</td> <td align="right">400</td> <td align="right">1</td> <td align="right">100.00</td> <td align="right">0.00</td> </tr> <tr> <td>392859</td> <td>Vine </td> <td>S S</td> <td>PO Box 79 </td> <td>Broton</td> <td>VT</td> <td align="right">5046</td> <td align="right">700</td> <td align="right">1</td> <td align="right">439.00</td> <td align="right">0.00</td> </tr> <tr> <td>938485</td> <td>Johnson </td> <td>J A</td> <td>3 Alpine Way </td> <td>Helen </td> <td>GA</td> <td align="right">30545</td> <td align="right">9999</td> <td align="right">2</td> <td align="right">3987.50</td> <td align="right">33.50</td> </tr> <tr> <td>397267</td> <td>Tyron </td> <td>W E</td> <td>13 Myrtle Dr </td> <td>Hector</td> <td>NY</td> <td align="right">14841</td> <td align="right">1000</td> <td align="right">1</td> <td align="right">0.00</td> <td align="right">0.00</td> </tr> <tr> <td>389572</td> <td>Stevens </td> <td>K L</td> <td>208 Snow Pass</td> <td>Denver</td> <td>CO</td> <td align="right">80226</td> <td align="right">400</td> <td align="right">1</td> <td align="right">58.75</td> <td align="right">1.50</td> </tr> <tr> <td>846283</td> <td>Alison </td> <td>J S</td> <td>787 Lake Dr </td> <td>Isle </td> <td>MN</td> <td align="right">56342</td> <td align="right">5000</td> <td align="right">3</td> <td align="right">10.00</td> <td align="right">0.00</td> </tr> <tr> <td>475938</td> <td>Doe </td> <td>J W</td> <td>59 Archer Rd </td> <td>Sutter</td> <td>CA</td> <td align="right">95685</td> <td align="right">700</td> <td align="right">2</td> <td align="right">250.00</td> <td align="right">100.00</td> </tr> <tr> <td>693829</td> <td>Thomas </td> <td>A N</td> <td>3 Dove Circle</td> <td>Casper</td> <td>WY</td> <td align="right">82609</td> <td align="right">9999</td> <td align="right">2</td> <td align="right">0.00</td> <td align="right">0.00</td> </tr> <tr> <td>593029</td> <td>Williams</td> <td>E D</td> <td>485 SE 2 Ave </td> <td>Dallas</td> <td>TX</td> <td align="right">75218</td> <td align="right">200</td> <td align="right">1</td> <td align="right">25.00</td> <td align="right">0.00</td> </tr> <tr> <td>192837</td> <td>Lee </td> <td>F L</td> <td>5963 Oak St </td> <td>Hector</td> <td>NY</td> <td align="right">14841</td> <td align="right">700</td> <td align="right">2</td> <td align="right">489.50</td> <td align="right">0.50</td> </tr> <tr> <td>583990</td> <td>Abraham </td> <td>M T</td> <td>392 Mill St </td> <td>Isle </td> <td>MN</td> <td align="right">56342</td> <td align="right">9999</td> <td align="right">3</td> <td align="right">500.00</td> <td align="right">0.00</td> </tr> </table>How a browser displays the generated HTML
The following table shows how the HTML source code looks when viewed in a browser.
Customer Number | Last Name | Initials | Street Address | City | State | Zip Code | Credit Limit | Charge Code | Balance Due | Credit Due |
---|---|---|---|---|---|---|---|---|---|---|
938472 | Henning | G K | 4859 Elm Ave | Dallas | TX | 75217 | 5000 | 3 | 37.00 | 0.00 |
839283 | Jones | B D | 21B NW 135 St | Clay | NY | 13041 | 400 | 1 | 100.00 | 0.00 |
392859 | Vine | S S | PO Box 79 | Broton | VT | 5046 | 700 | 1 | 439.00 | 0.00 |
938485 | Johnson | J A | 3 Alpine Way | Helen | GA | 30545 | 9999 | 2 | 3987.50 | 33.50 |
397267 | Tyron | W E | 13 Myrtle Dr | Hector | NY | 14841 | 1000 | 1 | 0.00 | 0.00 |
389572 | Stevens | K L | 208 Snow Pass | Denver | CO | 80226 | 400 | 1 | 58.75 | 1.50 |
846283 | Alison | J S | 787 Lake Dr | Isle | MN | 56342 | 5000 | 3 | 10.00 | 0.00 |
475938 | Doe | J W | 59 Archer Rd | Sutter | CA | 95685 | 700 | 2 | 250.00 | 100.00 |
693829 | Thomas | A N | 3 Dove Circle | Casper | WY | 82609 | 9999 | 2 | 0.00 | 0.00 |
593029 | Williams | E D | 485 SE 2 Ave | Dallas | TX | 75218 | 200 | 1 | 25.00 | 0.00 |
192837 | Lee | F L | 5963 Oak St | Hector | NY | 14841 | 700 | 2 | 489.50 | 0.50 |
583990 | Abraham | M T | 392 Mill St | Isle | MN | 56342 | 9999 | 3 | 500.00 | 0.00 |