Class SqlQuery


  • public class SqlQuery
    extends Object
    SqlQuery allows us to build a select statement and generate it in database-specific SQL syntax.

    Notable differences in database syntax are:

    Identifier quoting
    Oracle (and all JDBC-compliant drivers) uses double-quotes, for example select * from "emp". Access prefers brackets, for example select * from [emp]. mySQL allows single- and double-quotes for string literals, and therefore does not allow identifiers to be quoted, for example select 'foo', "bar" from emp.
    AS in from clause
    Oracle doesn't like AS in the from * clause, for example select from emp as e vs. select * from emp e.
    Column aliases
    Some databases require that every column in the select list has a valid alias. If the expression is an expression containing non-alphanumeric characters, an explicit alias is needed. For example, Oracle will barfs at select empno + 1 from emp.
    Parentheses around table names
    Oracle doesn't like select * from (emp)
    Queries in FROM clause
    PostgreSQL and hsqldb don't allow, for example, select * from (select * from emp) as e.
    Uniqueness of index names
    In PostgreSQL and Oracle, index names must be unique within the database; in Access and hsqldb, they must merely be unique within their table
    Datatypes
    In Oracle, BIT is CHAR(1), TIMESTAMP is DATE. In PostgreSQL, DOUBLE is DOUBLE PRECISION, BIT is BOOL.

NOTE: Instances of this class are NOT thread safe so the user must make sure this is accessed by only one thread at a time.

Author:
jhyde