Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
18.5 An Interactive Query Viewer
491
Listing 18.14 QueryViewer.java
package coreservlets;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
/** An interactive database query viewer. Connects to
* the specified Oracle or Sybase database, executes a query,
* and presents the results in a JTable.
*/
public class QueryViewer extends JFrame
implements ActionListener{
public static void main(String[] args) {
new QueryViewer();
}
private JTextField hostField, dbNameField,
queryField, usernameField;
private JRadioButton oracleButton, sybaseButton;
private JPasswordField passwordField;
private JButton showResultsButton;
private Container contentPane;
private JPanel tablePanel;
public QueryViewer () {
super("Database Query Viewer");
WindowUtilities.setNativeLookAndFeel();
addWindowListener(new ExitListener());
contentPane = getContentPane();
contentPane.add(makeControlPanel(), BorderLayout.NORTH);
pack();
setVisible(true);
}
/** When the "Show Results" button is pressed or
* RETURN is hit while the query textfield has the
* keyboard focus, a database lookup is performed,
* the results are placed in a JTable, and the window
* is resized to accommodate the table.
*/
public void actionPerformed(ActionEvent event) {
String host = hostField.getText();
String dbName = dbNameField.getText();
String username = usernameField.getText();
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved