Inserting data
insert(table, nullColumnHack, values)
Table: Tables Name
Nullcolumnhack: Default value for empty columns
Values: A map that encapsulates column names and columns, representing a single piece of data
Delete data
db.delete(table, whereClause, whereArgs)
Table: Tables Name
Whereclause: Delete condition, can contain wildcard character "? ”
Whereargs: Delete a conditional parameter array to populate wildcard characters
Querying data
db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
Table: Tables Name
Columns: Column an array group
Selection: A conditional where clause, which can contain wildcards "? ”
GroupBy: Grouping columns
Having: grouping conditions
ORDER BY: Row sequence
modifying data
db.update(table, values, whereClause, whereArgs)
Table: Name of values: Updated record information
Whereclause: Updated condition that can contain wildcard characters "? ”
Whereargs: An updated array of conditional values used to populate wildcard characters
Refer to the code for specific actions:
Public class myhelper extends sqliteopenhelper { Public StaticString db_name ="Note.db"; Public StaticString Tab_name ="Notes"; Public StaticString ID ="_id"; Public StaticString CONTENT ="Content"; Public StaticString DATE ="Date";PrivateSqlitedatabase DB; Public Myhelper(Context context) {Super(Context, Db_name,NULL,1); }/** * Called when creating a database * / @Override Public void onCreate(Sqlitedatabase db) { This. db = db; String sql =The CREATE TABLE notes (+ ID +"Integer primary key AutoIncrement,"+ CONTENT +"text,"+ DATE +"text)";//Build TableDb.execsql (SQL);//Insert some initial dataContentvalues values01 =NewContentvalues (); Values01.put (CONTENT,"I am the initial data one"); Values01.put (DATE, GETDATE ()); Contentvalues VALUES02 =NewContentvalues (); Values02.put (CONTENT,"I am the initial data two"); Values02.put (DATE, GETDATE ()); Db.insert (Tab_name,NULL, values01); Db.insert (Tab_name,NULL, VALUES02); }/** * Get current time * @return * * PublicStringgetdate() {Date dt =NewDate (); DateFormat DF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String nowtime = df.format (DT);returnNowtime; }/** * Insert data * @param Values * * Public void Insert(Contentvalues values) {db = Getwritabledatabase (); Db.insert (Tab_name,NULL, values); Db.close (); }/** * Delete data * @param Date * * Public void Delete(String date) {db = Getwritabledatabase (); Db.delete (Tab_name, DATE +"= ? ",NewString[] {date}); Db.close (); }/** * Query data * @return * * PublicCursorQuery() {db = Getwritabledatabase (); cursor cursor = db.query (Tab_name,NULL,NULL,NULL,NULL,NULL,NULL);returnCursor }/** * Update data * @param values * @param Date */ Public void Updata(Contentvalues values, String date) {db = Getwritabledatabase (); Db.update (Tab_name, values, DATE +"= ? ",NewString[] {date}); }/** * Call */When updating several libraries @Override Public void Onupgrade(Sqlitedatabase DB,intOldversion,intNewVersion) {//TODO auto-generated method stub}}
Initial use of Sqliteopenhelper