test
Class SimbadSQL

java.lang.Object
  extended bytest.SimbadSQL

public class SimbadSQL
extends java.lang.Object

Simple test class for SQL queries to Simbad using jdbc

Version:
1.0 April 2003
Author:
Marc Wenger

Field Summary
private  java.sql.Connection con
           
private static java.lang.String dbUrl
           
private static java.lang.String driver
           
private static java.lang.String passwd
           
private static java.io.PrintStream prt
           
private static java.lang.String username
           
 
Constructor Summary
SimbadSQL(java.lang.String dbname)
          SimbadSQL object constructor.
 
Method Summary
private  java.lang.String buildLine(int[] w, java.lang.String[] str)
          Build a result line from an array of width and an array of strings
 void close()
          Close the database.
 void dbInfo()
          Display metadata information about the database itself
 void dbTableInfo()
          Display metadata information about a particular table
 void displayResultSet(java.io.PrintStream prt, java.sql.ResultSet result, boolean displayResult)
          Display the result of a query.
private  java.lang.String[] getColNames(java.sql.ResultSet result)
          Returns a arraylist with the column names
private  int[] getColWidth(java.sql.ResultSet result)
          Returns a arraylist with the column width.
private static java.util.ArrayList getCommandsFromFile(java.lang.String filename)
           
 boolean hasRows(java.sql.ResultSet result)
          Checks if a result set contains at least one row
static void main(java.lang.String[] args)
           
 java.sql.ResultSet query(java.lang.String sqlCommand)
          Executes a query on the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driver

private static final java.lang.String driver
See Also:
Constant Field Values

dbUrl

private static final java.lang.String dbUrl
See Also:
Constant Field Values

username

private static final java.lang.String username
See Also:
Constant Field Values

passwd

private static final java.lang.String passwd
See Also:
Constant Field Values

prt

private static java.io.PrintStream prt

con

private java.sql.Connection con
Constructor Detail

SimbadSQL

public SimbadSQL(java.lang.String dbname)
SimbadSQL object constructor. When created, the connection is established, or the programme has died.

Method Detail

close

public void close()
Close the database. Returns even if it fails.


dbInfo

public void dbInfo()
Display metadata information about the database itself


dbTableInfo

public void dbTableInfo()
Display metadata information about a particular table


query

public java.sql.ResultSet query(java.lang.String sqlCommand)
Executes a query on the database.

Parameters:
sqlCommand - SQL command to execute
Returns:
true if the result contains at least one row, false otherwise

hasRows

public boolean hasRows(java.sql.ResultSet result)
Checks if a result set contains at least one row


getColNames

private java.lang.String[] getColNames(java.sql.ResultSet result)
Returns a arraylist with the column names

Returns:
the arraylist with column names in the column natural order

getColWidth

private int[] getColWidth(java.sql.ResultSet result)
Returns a arraylist with the column width. Column width will be at least as large as column names.

Returns:
the arraylist with column width in the column natural order

buildLine

private java.lang.String buildLine(int[] w,
                                   java.lang.String[] str)
Build a result line from an array of width and an array of strings


displayResultSet

public void displayResultSet(java.io.PrintStream prt,
                             java.sql.ResultSet result,
                             boolean displayResult)
Display the result of a query.


getCommandsFromFile

private static java.util.ArrayList getCommandsFromFile(java.lang.String filename)

main

public static void main(java.lang.String[] args)