home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / TableExample1.java < prev    next >
Text File  |  1998-02-26  |  2KB  |  64 lines

  1. /*
  2.  * @(#)TableExample1.java    1.4 97/10/14
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. /**
  22.  * A minimal example, using the JTable to view data from a database.
  23.  *
  24.  * @version 1.20 09/25/97
  25.  * @author Philip Milne
  26.  */
  27.  
  28. import com.sun.java.swing.*;
  29.  
  30. import java.awt.event.WindowAdapter;
  31. import java.awt.event.WindowEvent;
  32. import java.awt.Dimension;
  33.  
  34. public class TableExample1 {
  35.  
  36.     public TableExample1(String URL, String driver, String user, 
  37.                          String passwd, String query) {
  38.         JFrame frame = new JFrame("Table");
  39.         frame.addWindowListener(new WindowAdapter() {
  40.             public void windowClosing(WindowEvent e) {System.exit(0);}});
  41.         JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
  42.         dt.executeQuery(query); 
  43.  
  44.         // Create the table
  45.         JTable tableView = new JTable(dt); 
  46.  
  47.         JScrollPane scrollpane = JTable.createScrollPaneForTable(tableView);
  48.         scrollpane.setPreferredSize(new Dimension(700, 300)); 
  49.         
  50.         frame.getContentPane().add(scrollpane);
  51.         frame.pack();
  52.         frame.setVisible(true);
  53.     }
  54.     
  55.     public static void main(String[] args) {
  56.         if (args.length != 5) {
  57.             System.err.println("Needs database parameters eg. ..."); 
  58.             System.err.println("java TableExample1 \"jdbc:sybase://dbtest:1455/pubs2\" \"connect.sybase.SybaseDriver\" guest trustworthy \"select * from titles\""); 
  59.             return; 
  60.         }
  61.         new TableExample1(args[0], args[1], args[2], args[3], args[4]); 
  62.     }
  63. }
  64.