【摘要】 打开数据库
File file=new File(getContext().getExternalFilesDir(null),”learn.db”);
SQLiteDatabase database=SQLiteDatabase.openOrCreateDatabase(file,null);
12
遍历数据库中的所有表名
Cursor tables=dat…
打开数据库
File file=new File(getContext().getExternalFilesDir(null),"learn.db");
SQLiteDatabase database=SQLiteDatabase.openOrCreateDatabase(file,null);
遍历数据库中的所有表名
Cursor tables=database.rawQuery("select name from sqlite_master where type='table' order by name",null);
names=new String[tables.getCount()-1];
int i=0;
while(tables.moveToNext()){
//第一个不需要,去掉,将查询的信息保存在数组里 if (i!=0){ names[i-1]=tables.getString(0); } i++; } tables.close();
选取特定记录
sql = "select * from TableName where "+条件+" order by "+排序+" limit "+要显示多少条记录+" offset "+跳过多少条记录;
更新记录
database.execSQL(UPDATE 表名 SET 字段名 = 值 WHERE ID = 6);
创建表
database.execSQL("CREATE TABLE table_name (column1 CHAR(100),column2 CHAR(100))");
判断表是否存在,不存在就创建表
database.execSQL("CREATE TABLE IF NOT EXISTS user (number CHAR(100),password CHAR(100))");
插入数据
database.execSQL(String.format("INSERT INTO english (name) VALUES (\" %s \")",data.getString(data.getColumnIndex("firstColumnName"))));
此例子是插入文本数据
查询数据是去重数据
Cursor cursor=database.rawQuery(String.format("select DISTINCT name from english"),null);
文章来源: blog.csdn.net,作者:Crayon鑫,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/Crayonxin2000/article/details/116191315
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END