which function is there in android for the following java function--statement = database.createStatement(sqlStatement);?
public void execute(String sqlStatement) throws DBException {
Statement statement;
try {
statement = database.createStatement(sqlStatement);
statement.prepare();
statement.execute();
statement.close();
} catch (DatabaseException databaseException) {
throw new DBException(Class.class.getName(), "execute", databaseException.getMessage());
}
}
This is the function in java that i have开发者_如何学编程 to implement in android. In android how can i use the createstatement(), statement.prepare() and statement.execute() functions?
You can use "execSQL" if you want to execute any query.
e.g:
SQLiteDatabase db = null;
db.execSQL("INSERT INTO tableName(field1, field2)" + " Values('"
+ value1 + "', '" + value2 + "');");
if you want to fetch data from data base then use Cursor.
e.g:
Cursor c = null;
c = db.rawQuery(QUERY, null);
while (c.moveToNext()) {
String fname = c.getString(c.getColumnIndex("field1"));
String lname = c.getString(c.getColumnIndex("field2"));
}
精彩评论