/** * 添加到数据库 * @param v */ public void insert(View v) { String content = mEt.getText().toString().trim(); BaSEOpenHelper openHelper = new BaSEOpenHelper(mContext); sqliteDatabase db = openHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("username", content); db.insert("t_user",null, values); db.close(); //清空内容 mEt.setText(""); }
/** * 查询 * @param v */ public void query(View v) { BaSEOpenHelper openHelper = new BaSEOpenHelper(mContext); sqliteDatabase db = openHelper.getReadableDatabase(); Cursor cursor = db.query("t_user", new String[]{"username"}, null, null, null, null, null); if(cursor != null){ while(cursor.movetoNext()){ //遍历数据 String username = cursor.getString(0); System.out.println(username); } cursor.close(); } db.close(); }
public void insert(View view) { String username = et.getText().toString().trim(); Orocle orocle = new Orocle(this); sqliteDatabase db = orocle.getWritableDatabase(pwd); ContentValues values = new ContentValues(); values.put("username", username); db.insert("ngyb", null, values); db.close(); et.setText(""); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。