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 />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

import java.sql.*;<br />

import java.io.*;<br />

import javax.swing.*;<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

public class S<strong>to</strong>reAndRetrieveImage extends JApplet {<br />

// Connection <strong>to</strong> the database<br />

private Connection connection;<br />

// Statement for static SQL statements<br />

private Statement stmt;<br />

// Prepared statement<br />

private PreparedStatement pstmt = null;<br />

private DescriptionPanel descriptionPanel1<br />

= new DescriptionPanel();<br />

private JComboBox jcboCountry = new JComboBox();<br />

/** Creates new form S<strong>to</strong>reAndRetrieveImage */<br />

public S<strong>to</strong>reAndRetrieveImage() {<br />

try {<br />

connectDB(); // Connect <strong>to</strong> DB<br />

s<strong>to</strong>reDataToTable(); //S<strong>to</strong>re data <strong>to</strong> the table (including image)<br />

fillDataInComboBox(); // Fill in <strong>com</strong>bo box<br />

retrieveFlagInfo((String)(jcboCountry.getSelectedItem()));<br />

}<br />

catch (Exception ex) {<br />

ex.printStackTrace();<br />

}<br />

}<br />

jcboCountry.addItemListener(new ItemListener() {<br />

public void itemStateChanged(ItemEvent evt) {<br />

retrieveFlagInfo((String)(evt.getItem()));<br />

}<br />

});<br />

add(jcboCountry, BorderLayout.NORTH);<br />

add(descriptionPanel1, BorderLayout.CENTER);<br />

private void connectDB() throws Exception {<br />

// Load the driver<br />

33

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

Saved successfully!

Ooh no, something went wrong!