连接Sqlite数据库

1.创建和更改数据库

1.1  规划数据库结构

CREATE TABLE(,, ...);

CREATE TABLE pets(_id INTEGER, name TEXT, breed TEXT, gender INTEGER,weight INTEGER);


两种不同的创建数据库表的方式,第一种硬编码,第二种利用已定义好的变量

String makeTableStatement="CREATE TABLE entry(_id INTEGER PRIMARY KEY,entryid TEXT,title TEXT, subtitle TEXT);"


String SQL = "CREATE TABLE" + FeedEntry.TABLE_NAME + "(" + FeedEntry._ID + "INTEGER PRIMARY KEY,"

FeedEntry.COLUMN_NAME_ENTRY_ID + "TEXT,"+

FeedEntry.COLUMN_NAME_TITLE + "TEXT );"


A Contract class

public class WeatherContract{

...

public static final class LocationEntry implements BaseColumns{

public static final String TABLE_NAME = "location";

public static final String COLUMN_CITY_NAME = "city_name";

public static final String COLUMN_COORD_LAT = "coord_lat";

public static final String COLUMN_COORD_LONG = "coord_long";

...

}

}

你可能感兴趣的:(连接Sqlite数据库)