browser
Class SQLBrowser

java.lang.Object
  extended by browser.Console
      extended by browser.SQLBrowser

public class SQLBrowser
extends Console

A command-line interpreter that executes SQL commands against a JDBC-compliant database. The default values of the driver, database, user, and password open my Oracle cs174 database running on Sigma. These must be changed to connect to other databases.


Field Summary
protected  java.sql.Connection connection
          The connection to a database is a JDBC object:
protected  java.lang.String dbasePrefix
          The specific database to be opened is identified by a URL of the form PROTOCOL:[@HOST:]PORT:NAME
protected  java.lang.String driverName
          A JDBC driver converts JDBC queries into database- specific commands.
protected  java.lang.String password
           
protected  java.sql.ResultSet result
          Executing most SQL statements results in a virtual table or view, which is represented in JDBC by a ResultSet object.
protected  java.sql.Statement statement
          Statement seems like a mis-named class.
protected  java.lang.String username
          Some databases require a login to connect.
 
Fields inherited from class browser.Console
prompt, stderr, stdin, stdout
 
Constructor Summary
SQLBrowser()
           
SQLBrowser(java.lang.String dbase)
          This constructor attempts to create a new database if the requested database can't be found.
 
Method Summary
 java.lang.String execute(java.lang.String sql)
          This method is called by the control loop in the Console class.
 void finalize()
           
protected  void help()
          This method is also called by the Console's control loop
static void main(java.lang.String[] args)
          Start the browser
private  java.lang.String toString(java.sql.ResultSet rs)
          Converts a result set into a formatted string semi-suitable for printing.
 
Methods inherited from class browser.Console
about, controlLoop, handle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driverName

protected java.lang.String driverName
A JDBC driver converts JDBC queries into database- specific commands. Thus, each type of database requires a specific driver.Sometimes the driver manager can automatically locate and load the appropritate driver. We explicitly load the appropriate driver, which means we must know its fully qualified name.


dbasePrefix

protected java.lang.String dbasePrefix
The specific database to be opened is identified by a URL of the form PROTOCOL:[@HOST:]PORT:NAME


username

protected java.lang.String username
Some databases require a login to connect. Put your Oracle user name and password here:


password

protected java.lang.String password

connection

protected java.sql.Connection connection
The connection to a database is a JDBC object:


statement

protected java.sql.Statement statement
Statement seems like a mis-named class. This is really an object that executes arbitrary SQL statements.


result

protected java.sql.ResultSet result
Executing most SQL statements results in a virtual table or view, which is represented in JDBC by a ResultSet object.

Constructor Detail

SQLBrowser

public SQLBrowser(java.lang.String dbase)
           throws java.sql.SQLException,
                  java.lang.ClassNotFoundException
This constructor attempts to create a new database if the requested database can't be found. It initializes connection and statement.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException

SQLBrowser

public SQLBrowser()
           throws java.sql.SQLException,
                  java.lang.ClassNotFoundException
Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
Method Detail

finalize

public void finalize()
              throws java.sql.SQLException
Overrides:
finalize in class java.lang.Object
Throws:
java.sql.SQLException

toString

private java.lang.String toString(java.sql.ResultSet rs)
                           throws java.sql.SQLException
Converts a result set into a formatted string semi-suitable for printing. The main significance of this method is that it shows how result sets are typically manipulated.

Throws:
java.sql.SQLException

execute

public java.lang.String execute(java.lang.String sql)
                         throws AppError
This method is called by the control loop in the Console class.

Specified by:
execute in class Console
Throws:
AppError

help

protected void help()
This method is also called by the Console's control loop

Overrides:
help in class Console

main

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