sqlite 学习
package com.example.sqlite;
import android.os.Bundle;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class SQLiteActivity extends Activity {
private TextView sqlitetext = null;
private Button createdatabase = null;
private Button updatabase = null;
private Button insert = null;
private Button updata = null;
private Button query = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlite_activity);
sqlitetext = (TextView)findViewById(R.id.sqlite);
createdatabase = (Button)findViewById(R.id.createdatabase);
updatabase = (Button)findViewById(R.id.updata);
insert = (Button)findViewById(R.id.insert);
updata = (Button)findViewById(R.id.updata);
query = (Button)findViewById(R.id.query);
sqlitetext.setText(R.string.sqlite);
createdatabase.setText(R.string.createdatabase);
updatabase.setText(R.string.updatadatabase);
insert.setText(R.string.insert);
updata.setText(R.string.updata);
query.setText(R.string.query);
createdatabase.setOnClickListener(new CreateListener());
}
class CreateListener implements OnClickListener {
public void onClick(View arg0) {
DatabaseHelper dbHelper = new DatabaseHelper(SQLiteActivity.this, "test_mars_db");
SQLiteDatabase db = dbHelper.getReadableDatabase();
}
}
}
再运行这个
package com.example.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int VERSION = 1;
public DatabaseHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
}
public DatabaseHelper(Context context, String name) {
this(context, name, VERSION);
}
public DatabaseHelper(Context context, String name, int VERSION) {
this(context, name, null, VERSION);
}
public void onCreate(SQLiteDatabase db) {
System.out.println("create a Database");
db.execSQL("create table user(id int,name varcher(20))");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
System.out.println("update a Database");
}
}