A connection is created or opened only after the Databasehelper getwritabledatabase () method or the Getreadabledatabase () method is called
- Sqlitedatabase db = Dbhelper.getreadabledatabase();
1. //execsql for executing SQL statements
- Db.execsql ("CREATE TABLE User (id int,name varchar)");
2,//Call the Insert method, you can insert data into the database
- ///First parameter: Table name
- ///second parameter: SQL does not allow an empty column, if Contentvalues is empty, then this column is explicitly indicated as a null value
- // Third parameter: Contentvalues object   
- Db.insert ("user", null, values);
3.//Call the update method
- ///First parameter string: Table name
- ///second parameter Contentvalues:contentvalues object
- ///The third parameter string:where sentence, equivalent to the statement in the SQL statement where? Number is a placeholder
- ///Fourth parameter string[]: The value of a placeholder
- db.update (" Id=? " , new string[] { " 1 "  });
4,//Call the Query method of the Sqlitedatabase object for querying, return a cursor object: Result set object returned by the database query
- ///First parameter string: Table name
- ///second parameter string[]: column name to query
- ///Third parameter string: Query condition
- ///Fourth parameter string[]: parameters of the query condition
- //Fifth parameter string: Groups The results of a query
- ///Sixth parameter string: Limits The results of a grouping
- //Seventh parameter string: Sort the results of a query
- cursor cursor = db.query (, new string[] { "id" ,  
- "name"  } , "id=?" , new string[] { " 1 " }, null, null, null
- //Moves the cursor to the next line to determine if the result set has the next data, returns True if any, and false if none
5.//Call the Delete method of the Sqlitedatabase object for deletion
///First parameter string: Table name
Second argument string: Conditional statement
Third parameter string[]: condition value
Sqlitedatabase.delete ("user", "id=?") , new string[]{"1"});
System.out.println ("----------Delete----------");