1. Android中對資料庫進行條件查詢
android讀取資料庫可以使用sqlite一些api進行讀取,實例如下:
/**
*
查找一條數據
*
@param
uid
*/
public
user
find(integer
uid){
sqlitedatabase
db=dbopenhelper.getreadabledatabase();
//創建資料庫輔助類
cursor
cursor
=db.rawquery("select
*
from
user
where
uid=?",
new
string[]{uid.tostring()});
//創建一個游標
if(cursor.movetofirst()){
//循環遍歷查找數組
int
uid2=cursor.getint(cursor.getcolumnindex("uid"));
string
uname=cursor.getstring(cursor.getcolumnindex("uname"));
string
uaddress=cursor.getstring(cursor.getcolumnindex("uaddress"));
user
user=new
user();
user.setuid(uid2);
user.setuname(uname);
user.setuaddress(uaddress);
return
user;
}
cursor.close();
return
null;
}
2. android 資料庫條數查詢方法
DBHelper 繼承SQLiteopenHelper
DBHelper helper=new DBHelper(......);
SQLitedatebase db=helper.getReadabledatabase();
db.exe("select count as totalcount from tablename");
3. ANDROID中的資料庫查詢 跪大神啊
public void query(char word) {
String[] columns = { "ID", "CNword", "BH" };// 表的column名稱
// 獲取資料庫實例,根據實際情況修改
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
"/data/data/com.example.cx/databases/ghydb.db", null);
Cursor cursor = null;
try {
cursor = database.query("hanzibihua", columns, "CNword=?",
new String[] { String.valueOf(word) }, null, null, null);
while (null != cursor && cursor.moveToNext()) {// 資料庫中一個漢字如果存有多個,循環獲取
cursor.getString(cursor.getColumnIndex("BH"));// 這里獲取筆畫
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally {
if (null != cursor) {
cursor.close();
}
}
}
4. android sqlite資料庫怎樣寫帶條件的查詢語句
c = db.rawQuery("select _id,ration,album_id,size,album_pic,artist_pic,title,data,album,artist,recentiy_time from musictbl where recentiy_time <> 0",null); 排序可以對list進行排序,在music類里實現一下排序的介面就可以了吧
5. Android中對資料庫進行條件查詢
你是用Cursor吧?當然不用moveToNext()了,但是好像讀取前要先moveToFrist(),因為一開始時指針是在最後一個數據後面,直接讀會報錯。
6. android 資料庫如何去查找某一條數據
select * from tableName where id = '1';唯一特定的欄位來確定一條記錄。
結構化查詢語言(Structured Query Language)簡稱SQL(發音:/ˈes
kjuː ˈel/ "S-Q-L"),是一種特殊目的的編程語言,是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。
結構化查詢語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統,
可以使用相同的結構化查詢語言作為數據輸入與管理的介面。結構化查詢語言語句可以嵌套,這使它具有極大的靈活性和強大的功能。
7. Android 資料庫裡面, 如何以id的值作為查詢條件,搜索到id為多少值對應的行的數據
你說的是sqlite資料庫吧,不應該叫android資料庫。我來舉個例你仿寫就行:
SQLiteDatabasedatabase=SQLiteDatabase.openOrCreateDatabase(
databaseFilename,null);//獲得.db文件的絕對路徑databaseFilename
Stringsql="selectscorefromlistwhereid='10'";//list是你的表名
Cursorcursor=database.rawQuery(sql,newString[]{});
while(cursor.moveToNext())
{
intnameColumnIndex1=cursor.getColumnIndex("score");
StringstrValue1=cursor.getString(nameColumnIndex1);
}
8. android資料庫查詢問題
rawQuery("select * from kechengbiao where week = ? and firstweek < ? and lastweek > ?", new String[]{weekday,"5","1"});
這樣得到的SQL查詢語句為:
select * from kechengbiao where week=weekday(這里應該是你的weekday代表的字元串) and firstweek < 5 and lastweek > 1
如果你想在SQL語句中使用字元串,需要在new String[]{}中修改,比如
rawQuery("select * from kechengbiao where kecheng = ?", new String[]{"'English'"});//注意English前後分別有一個雙引號和一個單引號
得到的SQL查詢語句為:
select * from kechengbiao where kecheng = 'English'
9. android SQLite資料庫查詢
這個很簡單的:
//打開或創建test.db資料庫
SQLiteDatabasedb = openOrCreateDatabase("test.db", Context.MODE_PRIVATE, null);
//創建person表
db.execSQL("DROPTABLE IF EXISTS person");
db.execSQL("CREATE TABLE person (_idINTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLINT)");
//插入數據
Personperson = new Person();
person.name= "john";
person.age = 30;
db.execSQL("INSERT INTO person VALUES(NULL, ?, ?)",new Object[]{person.name, person.age});
//讀取數據
Cursor c = db.rawQuery("SELECT* FROM person WHERE age >= ?", new String[]{"33"});
while (c.moveToNext()) {
int _id = c.getInt(c.getColumnIndex("_id"));
String name = c.getString(c.getColumnIndex("name"));
int age = c.getInt(c.getColumnIndex("age"));
Log.i("db", "_id=>" + _id + ", name=>" + name + ", age=>" + age);
}
c.close();
//關閉當前資料庫
db.close();
10. Android-Android用query怎麼進行多條件查詢或者其他方法
SQLiteDatabase 給我提供的方法很不實用,還是建議樓主自己寫sql語句,參數想怎麼傳都可以
例如:Cursor c = db.rawQuery("select * from user where username=? and password = ?",
new Stirng[]{"用戶名","密碼"});
如果你非要調用SQLiteDatabase的query方法,那可以這樣
db.query("表名", new String[]{"欄位1,欄位2"}, "條件1=? and 條件2=?", new String[]{"條件1的值,條件2的值"},null,null,null)