标签:
一、在Android中查询数据库用到两个重要的类:二、JAVA代码
//1定义: private final String DATABASE_PATH = "/data/data/com.android.providers.settings/databases"; private final String DATABASE_FILENAME = "settings.db"; SQLiteDatabase database; //2打开数据库: private SQLiteDatabase openDatabase() { try { // 获得dictionary.db文件的绝对路径 String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME; File dir = new File(DATABASE_PATH); // 打开/sdcard/dictionary目录中的dictionary.db文件 SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase( databaseFilename, null); return database; } catch (Exception e) { } return null; } //3查询数据库: System.out.println("*****************************select********************************"); database = openDatabase(); String name = null; Cursor cs=database.rawQuery("select * from secure where name=\"udp_url\"", null); //打印第三列参数值 while(cs.moveToNext()){ name = cs.getString(2); System.out.println(name); } cs.close(); database.close(); System.out.println("******************************select*******************************"); //4更新数据库: 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>
标签:
原文地址:http://blog.csdn.net/hearbeat/article/details/51355619