再来activity的内容
package org.winplus.sufing;import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;public class SecoandActivity extends Activity implements OnClickListener{
public static final String DB_NAME="My.db";
public static final int VERSION=1;
public MyHelper helper;
public SQLiteDatabase mydb;
private Spinner mySpinner;
private ArrayAdapter<String> adapter1;
private Button button1,button2,button3,button4,button5,button6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secoand);
button1=(Button)this.findViewById(R.id.button1);
button2=(Button)this.findViewById(R.id.button2);
button3=(Button)this.findViewById(R.id.button3);
button4=(Button)this.findViewById(R.id.button4);
button5=(Button)this.findViewById(R.id.button5);
button6=(Button)this.findViewById(R.id.button6);
mySpinner=(Spinner)this.findViewById(R.id.spinner1);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
button5.setOnClickListener(this);
button6.setOnClickListener(this);
//初始化数据库辅助对象
helper=new MyHelper(this, DB_NAME, null, VERSION);
try {
//获取可读写的SQLiteDatabase对象
mydb=helper.getWritableDatabase();
CreateTable();
} catch (SQLiteException e) {
// TODO: handle exception
mydb=helper.getReadableDatabase();
e.printStackTrace();
}
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.secoand, menu);
return true;
}

public void onClick(View v)
{
if(v==button1)//插入两条记录
{
InsertData();
}
else if(v==button2)//删除一条记录
{
DeleteData();
}
else if(v==button3)//修改记录
{
ModifyData();
}
else if(v==button4)//删除数据表
{
DeleteTable();
}
else if(v==button5)//查询数据库
{
QueryData();
}
else if(v==button6)//重建数据库
{
CreateTable();
}
}

void InsertData()
{
ContentValues values=new ContentValues();
values.put(helper.ID, 1);
values.put(helper.NAME, "孙刚");
values.put(helper.HEIGHT, 1.75);
mydb.insert(helper.TB_NAME, null, values);
mydb.execSQL("insert into studenttable(id,name,height) values(2,'张超',1.80)");
UpdateSpinner();
}

void UpdateSpinner()
{
QueryData();
}

void DeleteData()
{
mydb.delete(helper.TB_NAME, helper.ID, null);
UpdateSpinner();
}

void ModifyData()
{
ContentValues values=new ContentValues();
values.put(helper.NAME, "张华");
values.put(helper.HEIGHT, 1.60);
mydb.update(helper.TB_NAME, values, helper.ID, null);
UpdateSpinner();
}

void DeleteTable()
{
mydb.execSQL("DROP TABLE IF EXISTS "+helper.TB_NAME);
UpdateSpinner();
}

void CreateTable()
{
mydb.execSQL("CREATE TABLE IF NOT EXISTS "+helper.TB_NAME+"("+helper.ID+"integer primary key,"+helper.NAME+"text,"+helper.HEIGHT+"float)");
UpdateSpinner();
}


void QueryData()
{
adapter1=null;
mySpinner.setAdapter(adapter1);
Cursor result=mydb.query(false,"studenttable", null, null, null, null, null, null, null, null);
int count=result.getCount();
if(count==0)return;
String[] Str=new String[count];
result.moveToFirst();int i=0;
while(!result.isAfterLast())
{
int id=result.getInt(0);
String name=result.getString(1);
float height=result.getInt(2);
Str[i]=String.valueOf(id)+""+name+""+String.valueOf(height);
i++;
result.moveToNext();
}
result.close();
adapter1=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,Str);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_item);
//将adapter添加到spinner对象中
mySpinner.setAdapter(adapter1);
}

@Override
public void onDestroy()
{
if(mydb!=null)
{
mydb.close();
mydb=null;
}
super.onDestroy();
}
}
Myhelper
package org.winplus.sufing;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;public class MyHelper extends SQLiteOpenHelper {
public final String TB_NAME="studenttable";
public final String ID="id";
public final String NAME="name";
public final String HEIGHT="height";
public MyHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO 自动生成的构造函数存根
} @Override
public void onCreate(SQLiteDatabase db) {
// TODO 自动生成的方法存根
//db.execSQL("CREATE TABLE IF NOT EXISTS "+TB_NAME+"("+ID+"integer primary key,"+NAME+"text,"+HEIGHT+"float)");
//Log.d("创表", "创建了新表");
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO 自动生成的方法存根 }}