19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

private void retrieveFlagInfo(String name) {<br />

try {<br />

pstmt.setString(1, name);<br />

ResultSet rs = pstmt.executeQuery();<br />

if (rs.next()) {<br />

Blob blob = rs.getBlob(1);<br />

ImageIcon imageIcon = new ImageIcon(<br />

blob.getBytes(1, (int)blob.length()));<br />

descriptionPanel1.setImageIcon(imageIcon);<br />

descriptionPanel1.setName(name);<br />

String description = rs.getString(2);<br />

descriptionPanel1.setDescription(description);<br />

}<br />

}<br />

catch (Exception ex) {<br />

System.err.println(ex);<br />

}<br />

}<br />

DescriptionPanel (line 14) is a <strong>com</strong>ponent for displaying a country<br />

(name, flag, and description). This <strong>com</strong>ponent was presented in Listing<br />

17.2, DescriptionPanel.java.<br />

The s<strong>to</strong>reDataToTable method (lines 58-95) populates the table with data.<br />

The fillDataInComboBox method (lines 97-102) retrieves the country names<br />

and adds them <strong>to</strong> the <strong>com</strong>bo box. The retrieveFlagInfo(name) method (lines<br />

104-121) retrieves the flag and description for the specified country<br />

name.<br />

Key Terms<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

BLOB type<br />

CLOB type<br />

batch mode<br />

cached row set<br />

row set<br />

scrollable result set<br />

updatable result set<br />

Chapter Summary<br />

1. This chapter developed a universal SQL client that can be used <strong>to</strong><br />

access any local or remote relational database.<br />

2. You can use the addBatch(SQLString) method <strong>to</strong> add SQL statements<br />

<strong>to</strong> a statement for batch processing.<br />

3. You can create a statement <strong>to</strong> specify that the result set be<br />

scrollable and updatable. By default, the result set is neither of<br />

these.<br />

4. The RowSet can be used <strong>to</strong> simplify <strong>Java</strong> database programming. A<br />

RowSet object is scrollable and updatable. A RowSet can fire a<br />

RowSetEvent.<br />

5. You can s<strong>to</strong>re and retrieve image data in JDBC using the SQL BLOB<br />

type.<br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!