Android Studio——SQLtie小型数据库初步

学习的内容如下:

1、SQLite介绍

SQLite是一个非常小的数据库。

2、SQLiteOpenHelper使用方法
当需要操作SQLite数据库的时候,首先必须要有一个SQLiteOpenHelper这样一个类的对象,而SQLiteOpenHelper这个类是一个抽象类,所以必须自己写一个类去继承他,编写好一个继承SQLiteOpenHelper的类后,这个类便拥有了如下两个常用的方法:
1.getReadableDatabase()
Create and/or open a database. 创建或打开一个只读的数据库对象。
2.getWritableDatabase()
Create and/or open a database that will be used for reading and writing. 创建货打开一个可读可写的对象。

除了上面的两个常用方法外,还有

abstract void onCreate(SQLiteDatabase db)
Called when the database is created for the first time.
void onOpen(SQLiteDatabase db)
Called when the database has been opened.

abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
Called when the database needs to be upgraded.
以上三个方法分别在创建数据库、打开数据库和更新数据库的时候调用。
3、使用adb访问SQLite

4、增删改查

贴上带有详细笔记的代码:

按键操作Activity部分:

在这里插入代码片
```package com.example.urien.sqlite;
 
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
public class SQLiteActivity extends AppCompatActivity {
 
    /**声明按钮控件*/
    private Button buttonCreateDatabase;
    private Button buttonUpdateDatabase;
    private Button buttonInsert;
    private Button buttonUpdate;
    private Button buttonQuery;
    private Button buttonDelete;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sqlite);
 
        /**找到按钮*/
        buttonCreateDatabase = findViewById(R.id.buttonCreateDatabase);
        buttonUpdateDatabase = findViewById(R.id.buttonUpdateDatabase);
        buttonInsert = findViewById(R.id.buttonInsert);
        buttonUpdate = findViewById(R.id.buttonUpdate);
        buttonQuery = findViewById(R.id.buttonQuery);
        buttonDelete = findViewById(R.id.buttonDelete);
 
        /
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值