当前位置:网站首页>Create a database and use
Create a database and use
2022-06-27 15:29:00 【Android Trainee】
1. Create database class inheritance SQLiteOpenHelper, In rewriting onCreate() Call in method db.execSQL(CREATE_BOOK)sql Statement create database , The name is Book.
public class MyDatabaseHelper extends SQLiteOpenHelper {
public static final String CREATE_BOOK = "create table Book ("
+ "phone integer primary key , "
+ " username text , "
+ "images BLOB ,"
+ "password text )";
public static final String CREATE_ADDRESS = "create table Address ("
+ "number text , "
+ "name text )";
private Context mContext;
public MyDatabaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_BOOK);
db.execSQL(CREATE_ADDRESS);
Toast.makeText(mContext, "Create succeeded", Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
2. Use in activities SQLiteDatabase Add, delete, modify, etc
MyDatabaseHelper dbHelper_address = new MyDatabaseHelper(getActivity(), "BookStore.db", null, 1);
SQLiteDatabase db_address = dbHelper_address.getWritableDatabase();
db_address.execSQL("delete from Address where name = ?", new String[]{name1});;// Delete
db_address.execSQL("insert into Address (number, name) values( ? , ?)",
new String[]{number, name});// increase
Cursor cursorsearch = db_address.rawQuery("select * from Address where name like '%"+search+"%'" , null);
while (cursorsearch.moveToNext()) {
@SuppressLint("Range") String sname = cursorsearch.getString(cursorsearch.getColumnIndex("name"));
@SuppressLint("Range") String snumber = cursorsearch.getString(cursorsearch.getColumnIndex("number"));
Address_item_bean searchInfo = new Address_item_bean(sname, snumber);
list2.add(searchInfo); }
cursorsearch.close();// Inquire about
边栏推荐
- 洛谷_P1003 [NOIP2011 提高组] 铺地毯_暴力枚举
- 2022-06-27日报:Swin Transformer、ViT作者等共话:好的基础模型是CV研究者的朴素追求
- Longest substring without repeated characters (Sword finger offer 48)
- [WUSTCTF2020]girlfriend
- 522. longest special sequence II / Sword finger offer II 101 Split equal sum subset
- On traversal of tree nodes
- R language triple becomes matrix matrix becomes triple
- How QT sets some areas to be transparent in the background image
- 反射学习总结
- All you want to know about large screen visualization is here
猜你喜欢

Fundamentals of software engineering (I)

Web chat room system based on SSM
![[high concurrency] deeply analyze the callable interface](/img/24/33c3011752c8f04937ad68d85d4ece.jpg)
[high concurrency] deeply analyze the callable interface

Talk about redis transactions

Why can't the start method be called repeatedly? But the run method can?

直播app运营模式有哪几种,我们该选择什么样的模式?

E ModuleNotFoundError: No module named ‘psycopg2‘(已解决)

2022-2-15 learning the imitated Niuke project - Section 5 shows comments

ReentrantLock、ReentrantReadWriteLock、StampedLock

AQS抽象队列同步器
随机推荐
What are the operating modes of the live app? What mode should we choose?
All you want to know about large screen visualization is here
VS编译遇到的问题
PCL Library - error reporting solution: cmake and Anaconda conflicts during installation
AI begets the moon, and thousands of miles share the literary heart
Unity3d best practices: folder structure and source control
Indexeddb learning materials
易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
Design and implementation of food recipe and ingredients website based on vue+node+mysql
ERROR L104: MULTIPLE PUBLIC DEFINITIONS
Go error collection | when a function uses a return value with a parameter name
Web chat room system based on SSM
AutoCAD - line width setting
sql注入原理
How is the London Silver point difference calculated
Longest substring without repeated characters (Sword finger offer 48)
洛谷入门1【顺序结构】题单题解
Pisa-Proxy 之 SQL 解析实践
AQS Abstract queue synchronizer
16 -- 删除无效的括号