first, querying the database in Android uses two important classes:
1.SQLiteDatabase: Used to create, delete, execute SQL commands, and perform other common database administration tasks.
2.query (string table, string[] columns, string selection, string[] Selectionargs, String groupBy, string having, Str ing)
returns the Cursor object
Table : Names of tables inside the database
columns: Need to query out database column array
selection: The database query condition, which is equivalent to the condition behind the where. If not, use NULL instead
Selectionargs: Database where conditions are often followed? Number, this is it? Replacement of the number. If not, use NULL instead
GroupBy: Whether the queried data needs to be grouped. If not, use NULL instead
Having : aggregation operation. If not, use NULL instead
ORDER BY: Whether the queried data needs to be sorted. If not, use NULL instead
Cursor: Query The result object returned by the database.
IsFirst (): Returns whether the cursor is pointing to the first row.
islast (): Returns whether the cursor points to the last row.
Movetofirst (): Moves the cursor to the first line.
movetolast (): Moves the cursor to the last line.
MoveToNext (): Moves the cursor to the next line.
movetoposition (int position): Moves the cursor to an absolute position.
movetoprevious (): Moves the cursor to the previous line.
Getcolumnindex (String columnName): Gets the column index, starting with 0
Getcolumnindexorthrow (String columnName): Returns the zero-based index of the given column name
Second, Java code
1 definition: Private final String Database_path = "/data/data/com.android.providers.settings/databases"; Private final String database_filename = "settings.db"; Sqlitedatabase database; 2 Open database: Private Sqlitedatabase OpenDatabase () {try {//Get absolute path to dictionary.db file String DatabaseFileName = Database_path + "/" + database_filename; File dir = new file (Database_path); Open the Dictionary.db file in the/sdcard/dictionary directory sqlitedatabase database = Sqlitedatabase.openorcreatedatabase ( DatabaseFileName, NULL); return database; } catch (Exception e) {} return null; }//3 Query database: System.out.println ("*****************************select********************************");d atabase = OpenDatabase (); String name = NULL; Cursor cs=database.rawquery ("SELECT * from secure where name=\" udp_url\ "", null); Print the third column parameter value while (Cs.movetonext ()) { Name = Cs.getstring (2); SYSTEM.OUT.PRINTLN (name); } cs.close (); Database.close (); System.out.println ("******************************select*******************************");// 4 Update Database: System.out.println ("****************************update*********************************"); Database = OpenDatabase (); Cursor cs=database.rawquery ("Update secure Set Value =\" "+ str +" \ "where name= ' Udp_url '", null); while (Cs.movetonext ()) {String name = cs.getstring (2); SYSTEM.OUT.PRINTLN (name); } cs.close (); Database.close (); System.out.println ("****************************update*********************************");</span>
Android Java Layer Operations database