SQL
这次的作业是要实现数据库的添加与删除
首先是XML布局
<LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btn_add" android:text="添加" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"/> <Button android:id="@+id/btn_update" android:text="修改" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"/> <Button android:id="@+id/btn_delete" android:text="删除" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"/> </LinearLayout>
然后是JavaActivity
public class NameDAO { private Context context;//上下文 private MyDBHelper helper;//创建,升级,打开数据库 private SQLiteDatabase db;//对表增删改查 public NameDAO(Context context){ helper=new MyDBHelper(context); } public void insert(Name name){ //打开数据库 db=helper.getWritableDatabase(); //生成数据集合 ContentValues values=new ContentValues(); values.put("name",name.getName()); //执行语句 db.insert("student",null,values); } public Cursor selectAll() { db =helper.getReadableDatabase(); Cursor cursor= db.query("student",null,null,null,null,null,null); return cursor; } public void delete(int id){ db = helper.getWritableDatabase(); db.delete("student","_id=?",new String[]{String.valueOf(id)});//根据数据的id号来删除数据 }


没了
浙公网安备 33010602011771号