eclipse中sqlite数据库
是这样的
先给代码
这是HELPER累
package fty.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class sqliteOpenHelper extends SQLiteOpenHelper{
private static final int VERSION = 1;
public sqliteOpenHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public sqliteOpenHelper(Context context, String name,
int version) {
this(context, name,null,version);
// TODO Auto-generated constructor stub
}
public sqliteOpenHelper(Context context, String name )
{
this(context, name,VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
System.out.println("create a Database");
db.execSQL("create table user(id int,name varchar(20))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
package fty.sqlite;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class sqliteActivity extends Activity {
private Button createDatabase;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createDatabase = (Button)findViewById(R.id.createDatabase);
createDatabase.setOnClickListener(new createListener());
}
class createListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sqliteOpenHelper helper = new sqliteOpenHelper(sqliteActivity.this,"sqliteTest");
SQLiteDatabase sqlite = helper.getReadableDatabase();
}}
}
在点击按钮后 数据库创建了 然后如图进入 但是不知道为什么进不了数据库呢?!视频上直接就进去了啊!这个SQLite是不是还得安装啊 还是eclipse里边直接有啊 还是怎么回事啊?!