Java Q&A          
by Cliff Berg


Example 1: 

public java.sql.Connection initConnection();
public void closeConnection();
public String toHTML(ResultSet r);
public Vector vselect(String sqline);
public ResultSet select(String sqline);

Example 2:

con = DriverManager.getConnection(protocol + "//" + host + "/" + dsn, uid, pwd);
dbmd = con.getMetaData(); 
con.setAutoCommit(true);


Example 3: 

Statement stmt = con.createStatement();
r = stmt.executeQuery(sqline);


Example 4: 

ResultSetMetaData rmd = r.getMetaData();
int cc = rmd.getColumnCount();

int i = 0;
while (r.next())
{
  i++;
  applet.showStatus("Retrieving row " + i);
  Object[] oa = new Object[cc];
  for (int j = 0; j < cc; j++)
  {
    Object o = r.getObject(j+1);
    if (o == null) o = "";
    oa[j] = o;
  }
  v.addElement(oa);
}


Listing One
/* Copyright (c) Digital Focus, 1996, 1997.
 * This code may be used for non-commercial purposes.
 * Digital Focus gives no warrantee or guarantee.
 */

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;

/** Query Tool.  */
public class Client extends Applet
{
    TextArea queryWindow = new TextArea(3, 40);
    Button go = new Button("Execute");
    QuerySvcsImpl querySvcs;

    /** Initialize the applet. */
    public void init()
    {
        add(queryWindow);
       add(go);
        // Instantiate query services
        try
        {
            querySvcs = new QuerySvcsImpl(getParameter("protocol"), 
               getParameter("host"), getParameter("dsn"), getParameter("uid"), 
               getParameter("pwd"));
        }
        catch (java.sql.SQLException ex)
        {
            ex.printStackTrace();
            showStatus(ex.getMessage());
            return;
        }
    }
    /** Handle the button press event. */
    public boolean handleEvent(Event e)
    {
        if ((e.target == go) && (e.id == Event.ACTION_EVENT))
        {
            java.sql.ResultSet r = null;
            String html = null;
            URL url = null;

            try
            {
                r = querySvcs.select(queryWindow.getText());
                html = querySvcs.toHTML(r);
                System.out.println(html);
                url = new URL("javascript:'" + html + "'");
                getAppletContext().showDocument(url, "results_window");
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                showStatus(ex.getMessage());
                return true;
            }
            return true;
        }
        else return super.handleEvent(e);
    }
}




