ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/sqlquerybuilderpaneexample.htm

180 lines
6.5 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using SQLQueryBuilderPane" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="sqlquerybuilderpaneexample" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using SQLQueryBuilderPane</title>
</head>
<body id="sqlquerybuilderpaneexample"><a name="sqlquerybuilderpaneexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using SQLQueryBuilderPane</h1>
<div><p></p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information.</div>
</div>
<div class="section"><div class="p"><pre>/////////////////////////////////////////////////////////////////////////
//
// SQLQueryBuilderPane example. This program presents a query builder
// which allows the user to build a SQL query.
//
// Command syntax:
// SQLQueryBuilderPaneExample system
//
// This source is an example of IBM Toolbox for Java "SQLQueryBuilderPane",
// and "SQLResultSetFormPane".
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class SQLQueryBuilderPaneExample
{
// This connection is shared by all components.
private SQLConnection connection;
// This error handler is shared by all components.
private ErrorDialogAdapter errorHandler;
// The query builder pane.
private SQLQueryBuilderPane queryBuilderPane;
// This is the main java calls. Here we create an instance of our
// class and call our own Main() method. We do this to avoid
// problems with static. Java has some restrictions with static
// methods using non-static data, especially when it comes to
// inner classes. The code is cleaner if we keep the amount of
// static data and methods to a minimum.
public static void main (String[] args)
{
SQLQueryBuilderPaneExample me = new SQLQueryBuilderPaneExample();
me.Main(args);
}
public void Main (String[] args)
{
// If a system was not specified, then display
// help text and exit.
if (args.length != 1)
{
System.out.println("Usage: SQLQueryBuilderPaneExample system");
return;
}
try
{
// Register the IBM Toolbox for Java JDBC driver.
DriverManager.registerDriver (new AS400JDBCDriver ());
// Create an SQLConnection object. The system name was passed
// as the first command line argument.
connection = new SQLConnection ("jdbc:as400://" + args[0]);
// Create a frame.
JFrame f = new JFrame ("SQLQueryBuilderPane example");
// Create an error dialog adapter. This will display
// any errors to the user.
errorHandler = new ErrorDialogAdapter (f);
// Create a SQL query builder pane to present the query
// builder. Load the data that is needed for the query
// builder from the system.
queryBuilderPane = new SQLQueryBuilderPane (connection);
queryBuilderPane.addErrorListener (errorHandler);
queryBuilderPane.load ();
// Create a button which will display the results of
// the generated query in a form pane in another frame.
JButton resultSetButton = new JButton ("Show result set");
resultSetButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent event)
{
showFormPane (queryBuilderPane.getQuery ());
}
});
// When the frame closes, exit.
f.addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent event)
{
System.exit (0);
}
});
// Layout the frame with the query builder pane.
f.getContentPane ().setLayout (new BorderLayout ());
f.getContentPane ().add ("Center", queryBuilderPane);
f.getContentPane ().add ("South", resultSetButton);
f.pack ();
f.show ();
}
catch (Exception e)
{
System.out.println ("Error: " + e.getMessage ());
System.exit (0);
}
}
private void showFormPane (String query)
{
// Create a new frame for the results of the query.
JFrame f = new JFrame (query);
// Create a SQL result set form pane to present the results
// of the query. Load the results from the system.
SQLResultSetFormPane formPane = new SQLResultSetFormPane (connection, query);
formPane.addErrorListener (errorHandler);
formPane.load ();
// Layout the frame with the form pane.
f.getContentPane ().setLayout (new BorderLayout ());
f.getContentPane ().add ("Center", formPane);
f.pack ();
f.show ();
}
}</pre>
</div>
</div>
</div>
</body>
</html>