Andriod的数据持久化和数据库操作

今天我学习了Andriod的数据持久化和数据库操作。为了更好地了解这些内容,我创建了一个简单的Note应用程序,并将笔记存储在SQLite数据库中。以下是代码:

public class Note {

    private int id;

    private String title;

    private String content;

 

    public int getId() {

        return id;

    }

 

    public void setId(int id) {

        this.id = id;

    }

 

    public String getTitle() {

        return title;

    }

 

    public void setTitle(String title) {

        this.title = title;

    }

 

    public String getContent() {

        return content;

    }

 

    public void setContent(String content) {

        this.content = content;

    }

}

 

```java

public class NoteDatabaseHelper extends SQLiteOpenHelper {

private static final String DB_NAME = "note.db";

private static final int DB_VERSION = 1;

 

public NoteDatabaseHelper(@Nullable Context context) {

    super(context, DB_NAME, null, DB_VERSION);

}

 

@Override

public void onCreate(SQLiteDatabase sqLiteDatabase) {

    sqLiteDatabase.execSQL("CREATE TABLE note (" +

            "id INTEGER PRIMARY KEY AUTOINCREMENT," +

            "title TEXT," +

            "content TEXT)");

}

 

posted @ 2023-05-22 21:17  ITJAMESKING  阅读(8)  评论(0编辑  收藏  举报