android sqlite 数据库创建,在android中创建SQLite数据库

好的例子是 here。 try { myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE

好的例子是

here。

try {

myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);

/* Create a Table in the Database. */

myDB.execSQL("CREATE TABLE IF NOT EXISTS "

+ TableName

+ " (Field1 VARCHAR, Field2 INT(3));");

/* Insert data to a Table*/

myDB.execSQL("INSERT INTO "

+ TableName

+ " (Field1, Field2)"

+ " VALUES ('Saranga', 22);");

/*retrieve data from database */

Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);

int Column1 = c.getColumnIndex("Field1");

int Column2 = c.getColumnIndex("Field2");

// Check if our result was valid.

c.moveToFirst();

if (c != null) {

// Loop through all Results

do {

String Name = c.getString(Column1);

int Age = c.getInt(Column2);

Data =Data +Name+"/"+Age+"\n";

}while(c.moveToNext());

}