日期:2014-05-16 浏览次数:20588 次
---------------------------------------------.java
package com.example.sqlite;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends
Activity {
Button mButton1, mButton2,
mButton3;
MyDbHelper dbhelper;
SQLiteDatabase sqLiteDatabase;
private static final int old_VERSION = 1;
private static final int new_VERSION = 2;
@Override
public void onCreate(
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton1 = (Button) findViewById(R.id.button1);
mButton2 = (Button) findViewById(R.id.button2);
mButton3 = (Button) findViewById(R.id.button3);
mButton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// sqLiteDatabase = openOrCreateDatabase(
// DBNAME,
// Context.MODE_PRIVATE,
// null);
//
//
// if (sqLiteDatabase!=null) {
//
// Toast.makeText(getBaseContext(), "创建成功"+DBNAME, 2000).show();
// }
// else {
// Toast.makeText(getBaseContext(), "创建失败"+DBNAME, 2000).show();
// }
//
dbhelper=new MyDbHelper(getBaseContext(), old_VERSION);
sqLiteDatabase=dbhelper.getWritableDatabase();
Toast.makeText(getBaseContext(), "创建成功", 2000).show();
}
});
mButton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// sqLiteDatabase.close();
dbhelper=new MyDbHelper(getBaseContext(), new_VERSION);
sqLiteDatabase=dbhelper.getWritableDatabase();
Toast.makeText(getBaseContext(), &qu