home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 July / CHIP-1999-07.iso / software / jdk / jdk121.exe / disk1 / data1.cab / demos / demo / jfc / Table / TableExample1.java < prev    next >
Encoding:
Java Source  |  1999-03-27  |  1.8 KB  |  58 lines

  1. /*
  2.  * @(#)TableExample1.java    1.8 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /**
  16.  * A minimal example, using the JTable to view data from a database.
  17.  *
  18.  * @version 1.20 09/25/97
  19.  * @author Philip Milne
  20.  */
  21.  
  22. import javax.swing.*;
  23.  
  24. import java.awt.event.WindowAdapter;
  25. import java.awt.event.WindowEvent;
  26. import java.awt.Dimension;
  27.  
  28. public class TableExample1 {
  29.  
  30.     public TableExample1(String URL, String driver, String user,
  31.                          String passwd, String query) {
  32.         JFrame frame = new JFrame("Table");
  33.         frame.addWindowListener(new WindowAdapter() {
  34.             public void windowClosing(WindowEvent e) {System.exit(0);}});
  35.         JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
  36.         dt.executeQuery(query);
  37.  
  38.         // Create the table
  39.         JTable tableView = new JTable(dt);
  40.  
  41.         JScrollPane scrollpane = new JScrollPane(tableView);
  42.         scrollpane.setPreferredSize(new Dimension(700, 300));
  43.  
  44.         frame.getContentPane().add(scrollpane);
  45.         frame.pack();
  46.         frame.setVisible(true);
  47.     }
  48.  
  49.     public static void main(String[] args) {
  50.         if (args.length != 5) {
  51.             System.err.println("Needs database parameters eg. ...");
  52.             System.err.println("java TableExample1 \"jdbc:sybase://dbtest:1455/pubs2\" \"connect.sybase.SybaseDriver\" guest trustworthy \"select * from titles\"");
  53.             return;
  54.         }
  55.         new TableExample1(args[0], args[1], args[2], args[3], args[4]);
  56.     }
  57. }
  58.