Java Reference
In-Depth Information
Table 19-1: Supported Query Operators
Function
Operator
Comment
Equality
=
String.equals()
Inequality
<>
Comparison
LIKE
Supports the % wildcard character
Negation
NOT
Supports all the above
The base class used to process SQL commands is
XMLCommand
. This class is not XML specific,
despite its name. XML-specific functionality is handled by extending the class. That way, the class can
be used as the basis of any other SQL engine you may wish to build.
The XMLCommand class
One of the key methods of the
XMLCommand
class is the
parseSQLCmd()
method, which is used to
split the command into its main components clauses. These include the command itself, the table name,
the column names, and the
WHERE
clause. Additional utility methods such as
splitFields()
split
these clauses into vectors of subclauses for further processing.
Listing 19-9
shows the
XMLCommand
class.
Listing 19-9: XMLCommand class
package JavaDatabaseBible.ch19.JDBCforXML;
import java.sql.*;
import java.net.*;
import java.util.*;
/**
* XMLCommand is an implementation independent SQL command preprocessor
*/
public class XMLCommand {
protected String SQLString;
protected String cmd = null;
protected String tableName = null;
protected String columns = null;
protected String values = null;
protected String fields = null;
protected String where = null;
protected String orderBy = null;
public XMLCommand() {
}
public XMLCommand(String SQLString) {
this.SQLString = SQLString.toUpperCase().trim();