喜 我想要详细步骤和编程代码来连接android中的数据库
答案 0 :(得分:3)
import android.app.Activity;
import android.os.Bundle;
import android.database.sqlite.SQLiteDatabase;
public class SQLiteTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SQLiteDatabase db;
db = openOrCreateDatabase("DataBase.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
//do the task you want here
db.close();
}
}
完成任务后,永远不要忘记关闭数据库。要从数据库访问数据,请使用Cursor
。