當前位置:首頁 » 安卓系統 » androidsqlitein查詢

androidsqlitein查詢

發布時間: 2022-08-07 04:45:02

『壹』 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();

『貳』 安卓sqlite查詢單個數據

cr=db.query(String table, String[] columns, String selection, String[]
selectionArgs, String groupBy, String having, String orderBy)//這里的內容根據你的要求填,返回遊標cr

cr.moveToPosition(-1);//把cr先移動到最前面的位置,每次重新查詢的時候到要先把游標移動到-1

cr.moveToNext//將游標向下移動,可以作為while()循環的條件,當遍歷完以後就返回false,退出循環

cr.getString(0)//第一列,從0開始

cr.getString(1)//第二列,把這兩個分別放到兩個數組中去,如果你有更多列,就getString(2) (3),隨你

這樣就能完成你的要求了

『叄』 怎樣對android開發中的sqlite資料庫進行模糊查詢,並返回一個Cursor

Android中SQLite模糊查詢,可以直接使用Cursor 的query加入模糊查詢的條件即可。
使用query有如下方式:
1.使用這種query方法%號前不能加',以下為示例代碼:
Cursor c_test = mDatabase.query(tab_name, new String[]{tab_field02}, tab_field02+" LIKE ? ",
new String[] { "%" + str[0] + "%" }, null, null, null);

2.使用這種query方法%號前必須加',以下為示例代碼 :
Cursor c_test=mDatabase.query(tab_name, new String[]{tab_field02},tab_field02+" like '%" + str[0] + "%'", null, null, null, null);

3.使用這種方式必須在%號前加' ,以下為示例代碼 :
String current_sql_sel = "SELECT * FROM "+tab_name +" where "+tab_field02+" like '%"+str[0]+"%'";
Cursor c_test = mDatabase.rawQuery(current_sql_sel, null);

『肆』 請問下android studio中的資料庫sqlite怎麼打開來查詢編輯

  1. 創建一個SQLiteDatabase對象

  2. database=sQlite.getWritableDatabase();//sQlite是目標資料庫的實例,這里得到一個資料庫管理對象。

  3. database.execSQL("insert into person (no,name,hometown,grade)values(?,?,?,?)",new Object[]{no,name,hometown,grade});//使用這個對象執行sql語句對資料庫進行操作

  4. 下面演示一個查詢操作:(這里的Person為一個定義好的java bean對象,對應資料庫里每一條記錄的實體)

    Cursor cursor=database.rawQuery("select * from person where name=?", new String[]{name});
    while (cursor.moveToNext()){
    Person person=new Person();
    person.setNo(cursor.getString(cursor.getColumnIndex("no")));
    person.setName(cursor.getString(cursor.getColumnIndex("name")));
    person.setHometown(cursor.getString(cursor.getColumnIndex("hometown")));
    //通過名字獲得列索引
    person.setGrade(cursor.getString(cursor.getColumnIndex("grade")));

    }

『伍』 android連接sqlite資料庫,怎麼查詢資料庫裡面的數據

用DatabaseHelper類,獲得資料庫實例,然後用query方法查詢,具體參數看api吧。另外別忘記加許可權
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

『陸』 android 查詢時 報錯 no such table 放在RAW下的資料庫確實存在的 是什麼原因

按照官方的開發文檔http://www.activeandroid.com/一步步來的哦,裡面說了只要創建類對象,會自動綁定到數據表裡面去,所以我只是創建了數據模型,如:
@Table(name = "Items")
public class Item extends Model {
// If name is omitted, then the field name is used.
@Column(name = "Name")
public String name;

@Column(name = "Category")
public Category category;

public Item(){
super();
}
public Item(String name, Category category){
super();
this.name = name;
this.category = category;
}
}

『柒』 android開發sqlite查詢表中某一欄位的所有數據,並以數組形式表示

select 列名 from 表名 where 條件(就是你所說的列中某個值滿足的條件)。列的順序是建表時,語句創建的順序決定的。查詢出來的列的順序,是你查詢時寫的欄位的順序。如下:
表中欄位順序:
create table user(id int primary key,name text);這張表欄位順序就是id,name。
再將獲取的數據放入數組中。
建議使用三方資料庫框架,要簡單很多。
Android Study 之 玩轉GreenDao 3.2.2 點滴提升逼格~
http://www.apkbus.com/blog-904057-67980.html

『捌』 android SQLite中資料庫查詢,如何查詢一段時間內的記錄

SELECT * from TABLE_NAME t where jolianday(『now』)-jolianday(t.time)>7你試試這條SQL可以嗎

『玖』 關於android中使用SQLite資料庫的查詢基本操作.貼上代碼.

sqlite\.classpath
......\.project
......\.settings\org.eclipse.jdt.core.prefs
......\AndroidManifest.xml
......\bin\AndroidManifest.xml
......\...\classes\mars\sqlite3\BuildConfig.class
......\...\.......\....\.......\db\DatabaseHelper.class
......\...\.......\....\.......\R$attr.class
......\...\.......\....\.......\R$drawable.class
......\...\.......\....\.......\R$id.class
......\...\.......\....\.......\R$layout.class
......\...\.......\....\.......\R$string.class
......\...\.......\....\.......\R.class
......\...\.......\....\.......\SQLiteActivity$CreateListener.class
......\...\.......\....\.......\SQLiteActivity$InsertListener.class
......\...\.......\....\.......\SQLiteActivity$QueryListener.class
......\...\.......\....\.......\SQLiteActivity$UpdateListener.class
......\...\.......\....\.......\SQLiteActivity$UpdateRecordListener.class
......\...\.......\....\.......\SQLiteActivity.class
......\...\classes.dex
......\...\dexedLibs\annotations-.jar
......\...\jarlist.cache
......\...\res\drawable-hdpi\icon.png
......\...\...\.........ldpi\icon.png
......\...\...\.........mdpi\icon.png
......\...\resources.ap_
......\...\sqlite.apk
......\gen\mars\sqlite3\BuildConfig.java
......\...\....\.......\R.java
......\project.properties
......\res\drawable-hdpi\icon.png
......\...\.........ldpi\icon.png
......\...\.........mdpi\icon.png
......\...\layout\main.xml
......\...\values\strings.xml
......\src\mars\sqlite3\db\DatabaseHelper.java
......\...\....\.......\SQLiteActivity.java
......\bin\classes\mars\sqlite3\db
......\...\.......\....\sqlite3
......\src\mars\sqlite3\db
......\bin\classes\mars
......\...\res\drawable-hdpi
......\...\...\drawable-ldpi
......\...\...\drawable-mdpi
......\gen\mars\sqlite3
......\src\mars\sqlite3
......\bin\classes
......\...\dexedLibs
......\...\res
......\gen\mars
......\res\drawable-hdpi
......\...\drawable-ldpi
......\...\drawable-mdpi
......\...\drawable-xhdpi
......\...\layout
......\...\values
......\src\mars
......\.settings
......\assets
......\bin
......\gen
......\res
......\src
sqlite

『拾』 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類里實現一下排序的介面就可以了吧

熱點內容
零食劇情腳本 發布:2024-04-16 20:59:56 瀏覽:81
我的世界粘土伺服器戰牆 發布:2024-04-16 20:55:31 瀏覽:682
sql字元串的長度 發布:2024-04-16 20:50:18 瀏覽:185
glc配置一般為什麼那麼貴 發布:2024-04-16 20:49:35 瀏覽:269
如何開啟共享電腦伺服器 發布:2024-04-16 20:21:06 瀏覽:660
銳捷升級伺服器地址 發布:2024-04-16 20:11:46 瀏覽:251
淘寶登錄密碼忘記如何改密碼 發布:2024-04-16 20:11:36 瀏覽:792
塞班和安卓哪個好一點 發布:2024-04-16 20:08:05 瀏覽:207
python安裝環境變數 發布:2024-04-16 20:06:47 瀏覽:780
安卓平板怎麼用小米手柄玩游戲 發布:2024-04-16 20:06:39 瀏覽:299