com.mortbay.JDBC
Class Select

java.lang.Object
  |
  +--com.mortbay.JDBC.Clause
        |
        +--com.mortbay.JDBC.Select

public class Select
extends Clause

Select produces SQL SELECT statements.

Most of the clauses of a SELECT statement are supported, including SELECT DISTINCT, FROM, WHERE, ORDER BY. The WHERE subclauses can use either columns or values as the right hand side of expressions.

Notes

This class DOES NOT check the grammatical accuracy of the SQL statement produced.

Usage

 s = new Select();
 s.select(UserTable, NameColumn)
  .from(UserTable)
  .where(UserTable, AgeColumn,
         Select.GREATER_THAN,
         new Integer(30))
  .and()
  .where(UserTable,AgeColumn,
         Select.LESS_THAN,
         new Integer(50));
 Enumeration results = statement.query(db);
 while (answer.hasMoreElements())
 {
    Vector row = (Vector)answer.nextElement());
    String name = (String)row.firstElement();
 }
 

Version:
1.0 Fri Nov 21 1997
Author:
Jan Bartel (janb)
See Also:
Clause

Field Summary
static java.lang.String __SEPARATOR
           
static java.lang.String AND
           
static int DESC
          for ORDER BY clause
static boolean DISTINCT
          indicates if this select should use DISTINCT keyword
static java.lang.String EQUALS
           
static java.lang.String GREATER_THAN
           
static java.lang.String LESS_THAN
           
static java.lang.String LIKE
           
static java.lang.String NOT_EQUALS
          ANSI SQL standard operators and keywords
static java.lang.String OR
           
 
Constructor Summary
Select()
          Constructor.
Select(boolean distinct)
          Constructor.
 
Method Summary
 Select from(Table table)
          Add a table name to the FROM clause
static void main(java.lang.String[] args)
          main
 Select orderBy(Table table, Column column)
          Specify a column whose values should select the order of the results.
 Select orderSequence(int descending)
          ORDER DESCENDING, rather than ASCENDING
static java.lang.String qualifyName(Table table, Column column)
          Build a fully qualified name of the form: table.column
 java.util.Enumeration query(Database db)
          Build the query out of all of the clauses that have been established, and do it against the database
 Select select(Table table)
          Like SELECT *, but the actual column names are inserted.
 Select select(Table table, Column col)
          Add a subclause to the SELECT clause
static void test(Database db)
          test
 java.lang.String toString()
           
 
Methods inherited from class com.mortbay.JDBC.Clause
and, close, open, or, where, where, where, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISTINCT

public static final boolean DISTINCT
indicates if this select should use DISTINCT keyword

DESC

public static final int DESC
for ORDER BY clause

NOT_EQUALS

public static final java.lang.String NOT_EQUALS
ANSI SQL standard operators and keywords

EQUALS

public static final java.lang.String EQUALS

LESS_THAN

public static final java.lang.String LESS_THAN

GREATER_THAN

public static final java.lang.String GREATER_THAN

AND

public static final java.lang.String AND

OR

public static final java.lang.String OR

LIKE

public static final java.lang.String LIKE

__SEPARATOR

public static final java.lang.String __SEPARATOR
Constructor Detail

Select

public Select(boolean distinct)
Constructor.
Parameters:
name - - name for the query

Select

public Select()
Constructor.
Method Detail

select

public Select select(Table table,
                     Column col)
Add a subclause to the SELECT clause
Parameters:
table -  
col -  

select

public Select select(Table table)
Like SELECT *, but the actual column names are inserted.
Parameters:
table -  

from

public Select from(Table table)
Add a table name to the FROM clause
Parameters:
table -  

orderBy

public Select orderBy(Table table,
                      Column column)
Specify a column whose values should select the order of the results.
Parameters:
table -  
column -  

orderSequence

public Select orderSequence(int descending)
ORDER DESCENDING, rather than ASCENDING
Parameters:
descending -  

query

public java.util.Enumeration query(Database db)
                            throws java.sql.SQLException
Build the query out of all of the clauses that have been established, and do it against the database
Parameters:
db -  
Returns:
 
Throws:
java.sql.SQLException -  

toString

public java.lang.String toString()
Overrides:
toString in class Clause
Returns:
- the query as a string

qualifyName

public static java.lang.String qualifyName(Table table,
                                           Column column)
Build a fully qualified name of the form: table.column
Parameters:
table -  
column -  
Returns:
 

test

public static void test(Database db)
test

main

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