home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 2.2 KB | 64 lines |
- /*
- * @(#)TableExample1.java 1.4 97/10/14
- *
- * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the confidential and proprietary information of Sun
- * Microsystems, Inc. ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- */
-
- /**
- * A minimal example, using the JTable to view data from a database.
- *
- * @version 1.20 09/25/97
- * @author Philip Milne
- */
-
- import com.sun.java.swing.*;
-
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.Dimension;
-
- public class TableExample1 {
-
- public TableExample1(String URL, String driver, String user,
- String passwd, String query) {
- JFrame frame = new JFrame("Table");
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {System.exit(0);}});
- JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
- dt.executeQuery(query);
-
- // Create the table
- JTable tableView = new JTable(dt);
-
- JScrollPane scrollpane = JTable.createScrollPaneForTable(tableView);
- scrollpane.setPreferredSize(new Dimension(700, 300));
-
- frame.getContentPane().add(scrollpane);
- frame.pack();
- frame.setVisible(true);
- }
-
- public static void main(String[] args) {
- if (args.length != 5) {
- System.err.println("Needs database parameters eg. ...");
- System.err.println("java TableExample1 \"jdbc:sybase://dbtest:1455/pubs2\" \"connect.sybase.SybaseDriver\" guest trustworthy \"select * from titles\"");
- return;
- }
- new TableExample1(args[0], args[1], args[2], args[3], args[4]);
- }
- }
-