|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Statement
The representation of a SQL statement. The lifecycle of a statement:
Database.createStatement(String)
Statement.prepare()
Statement.bind(int, int) and associated methods, starting from 1 for the first formal.
Statement.getCursor(), which returns a Cursor
Statement.execute()()
Statement.reset() reverts the statement to step #3.
Statement.reset().
DatabaseException to be thrown.
// Create a selection statement with the bounds left as sequentially assigned parameters Statement s = "SELECT * FROM T WHERE a < ? AND a > ?"; s.prepare(); s.bind(1, upperBound); // an integer specifying the upper bound. s.bind(2, lowerBound); // an integer specifying the lower bound. Cursor c = s.getCursor(); // Now iterate over the data set using the Cursor. ...The statement may be used with explicitly numbered values as well:
Statement s = "SELECT * FROM T WHERE a < ?5 AND a > ?12";In this case, bind() should be used with the value numbers:
s.bind(5, upperBound); // an integer specifying the upper bound. s.bind(12, lowerBound); // an integer specifying the lower bound.
When parameters are used such as '?' to be a placeholder, the getFormalName() method will not return a parameter name. For example: "SELECT * FROM T WHERE a = ?" will not return the parameter name for "a".
It is necessary to provide a name in the query for getFormalName to return the parameter name. For example: "SELECT * FROM T WHERE a = :a" will return ":a" when calling getFormalName(1);
| Method Summary | ||
|---|---|---|
|
void |
bind(int index,
boolean value)
Binds a boolean parameter in the statement. |
|
void |
bind(int index,
byte value)
Binds a byte parameter in the statement. |
|
void |
bind(int index,
byte[] value)
Binds a byte[] parameter in the statement. |
|
void |
bind(int index,
byte[] value,
int offset)
Binds a byte[] parameter in the statement. |
|
void |
bind(int index,
byte[] value,
int offset,
int length)
Binds a byte[] parameter in the statement. |
|
void |
bind(int index,
double value)
Binds a double parameter in the statement. |
|
void |
bind(int index,
float value)
Binds a float parameter in the statement. |
|
void |
bind(int index,
int value)
Binds an integer parameter in the statement. |
|
void |
bind(int index,
String value)
Binds a String parameter in the statement. |
|
void |
bind(int index,
long value)
Binds a long parameter in the statement. |
|
void |
bind(int index,
short value)
Binds a short parameter in the statement. |
|
void |
close()
Closes the current statement, releases all resources. |
|
void |
execute()
Executes an update statement. |
|
String[] |
getColumnNames()
Get the names of the columns of this statement. |
|
Cursor |
getCursor()
Executes query statement and returns cursor with selected rows. |
|
int |
getFormalIndex(String paramName)
Convert the named sql parameter into a parameter index that can be used in bind() calls. |
|
String |
getFormalName(int index)
Convert a parameter index to a sql parameter name. |
|
int |
getParameterCount()
Return the largest index of all sql parameters in a statement or 0 if no SQL parameters. |
|
String |
getTail()
Get unparsed portion of a prepared statement -- the "tail". |
|
void |
prepare()
Prepare a statement for execution |
|
void |
reset()
Resets Statement to its state just after prepare(). |
|
void |
rewind()
|
| Method Detail |
|---|
void prepare()
throws DatabaseException
DatabaseException - - database is closed/null or a sql statement has already been prepared
String getTail()
throws DatabaseException
DatabaseException - - database is closed/null or the
statement has not been prepared.
void execute()
throws DatabaseException
This method should be called only with 'update' type statements that do not return result set. These include INSERT, UPDATE, DELETE and similar sql statements.
Only the first call to this method performs data updates. Subsequent calls will be disregarded..
DatabaseExceptionStatement.getCursor()
Cursor getCursor()
throws DatabaseException
This method should be called only with SELECT type statements that return row set.
The first call to getCursor() creates a Cursor. Each subsequent call to getCursor() returns the same Cursor instance. reset() on the statement discards all bound values, and invalidates the current Cursor. A subsequent call to getCursor() allocates a fresh Cursor for the reset statement.
Note that returned cursor is positioned before the first row and any
attempts to get current row would fail. Navigate to the first row through
Cursor.first() or Cursor.next() methods.
DatabaseExceptionStatement.execute()
void bind(int index,
int value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
long value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
float value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
double value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
short value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
byte value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
boolean value)
throws DatabaseException,
DatabaseBindingException
true is bound as 1,
and false as 0.
index - Index of the parameter.value - The value to bind.
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
String value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind (null is also allowed)
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
byte[] value)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind (null can also be bound)
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
byte[] value,
int offset)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind (null can also be bound)offset - The offset from which to bind value[].
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void bind(int index,
byte[] value,
int offset,
int length)
throws DatabaseException,
DatabaseBindingException
index - Index of the parameter.value - The value to bind (null can also be bound)offset - The offset from which to bind value[].length - The number of bytes to take from value[].
DatabaseBindingException - - thrown when binding failed
DatabaseException - - thrown if an statement is unprepared (or closed), or the database is null (or closed)
void reset()
throws DatabaseException
Statement.getCursor() must be called to get a new Cursor.
DatabaseException
void rewind()
throws DatabaseException
DatabaseException - After a rewind, Statement.getCursor() must be called to get a new Cursor.
void close()
throws DatabaseException
DatabaseException
int getFormalIndex(String paramName)
throws DatabaseException,
DatabaseBindingException
DatabaseBindingException - - thrown when no matching parameter is found
DatabaseException - - thrown if an statement is unprepared or closed
String getFormalName(int index)
throws DatabaseException,
DatabaseBindingException
DatabaseBindingException - - thrown when no matching
parameter is found, or if the parameter with the given index is
an anonymous parameter.
DatabaseException - - thrown if an statement is unprepared or closed
String[] getColumnNames()
throws DatabaseException
DatabaseException - - thrown if an statement is unprepared or closed
int getParameterCount()
throws DatabaseException
Note that the sql parameters can be numbered arbitrarily if the ?NNN notation is used, in which case gaps might exist in the parameter list.
DatabaseException - - thrown if an statement is unprepared or closed
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.