public class Statement
extends java.lang.Object
Representation of a SQL statement. Depends of statement, different execute-methods
must be used.
1. use execute() for statement, that does not return any results(e.g. create/drop table/index/etc.)
2. use exeucteInsert() for INSERT-statement.
3. use exeucteUpdateOrDelete for DELETE/UPDATE statements
4. use executeSelect for SELECT-statements
Here 's an example of using SELECT-statement with parameter binding.
Database db = DatabaseFactory.openOrCreate(PATH_TO_DATABASE);
Statement s = db.prepareStatement("select * from TABLE_NAME where FIELD1 > ? and FIELD1 < ?");
s.bind(1,lowerBound);
s.bind(2,upperBound);
Cursor c = s.executeSelect();s
Note that this class is not thread safe.Constructor and Description |
---|
Statement() |
Modifier and Type | Method and Description |
---|---|
void |
bind(int index,
byte[] value)
Binds a byte array value to this statement.
|
void |
bind(int index,
double value)
Binds a double value to this statement.
|
void |
bind(int index,
int value)
Binds a integer value to this statement(32 bits).
|
void |
bind(int index,
long value)
Binds a long value to this statement(64 bits).
|
void |
bind(int index,
java.lang.String value)
Binds a String value to this statement.
|
void |
close()
Closes the statement
|
void |
execute()
Executes a SQL statement, that does not return any results.
|
long |
executeInsert()
Executes an INSERT statement and returns the ID of the inserted row.
|
Cursor |
executeSelect()
Executes a SELECT statement and returns a
Cursor over the result set. |
int |
executeUpdateOrDelete()
Executes an UPDATE or a DELETE statement and returns the number of affected rows.
|
void |
reset()
Clears all bindings.
|
public void execute() throws DatabaseException
DatabaseException
- if the statement could not be executed.public long executeInsert() throws DatabaseException
DatabaseException
- if the statement could not be executed.public int executeUpdateOrDelete() throws DatabaseException
DatabaseException
- if the statement could not be executed.public Cursor executeSelect() throws DatabaseException
Cursor
over the result set.DatabaseException
- if the statement could not be executed.public void bind(int index, byte[] value) throws DatabaseException
index
- - the 1-based indexvalue
- - the value to bindDatabaseException
public void bind(int index, double value) throws DatabaseException
index
- - the 1-based indexvalue
- - the value to bindDatabaseException
public void bind(int index, int value) throws DatabaseException
index
- - the 1-based indexvalue
- - the value to bindDatabaseException
public void bind(int index, long value) throws DatabaseException
index
- - the 1-based indexvalue
- - the value to bindDatabaseException
public void bind(int index, java.lang.String value) throws DatabaseException
index
- - the 1-based indexvalue
- - the value to bindDatabaseException
public void reset() throws DatabaseException
DatabaseException
public void close() throws DatabaseException
DatabaseException
- if the statement is already closed.