-
ContentValues執行對應的sql語句查看全部
-
创建文件: public class MainActivity extends Activity{ protected void onCreat(Bundle savedInstanceState){ super.onCreat(savedInstanceState); setContentView(R.layout.activity_main); File file=new File("/mnt/sdcard/test"); if(!file.exists()){ try{ file.createNewFile(); }catch(IOException e){ e.printStackTrace(); } }else{ Toast.makeText(MainActivity.this,"文件已存在",1000; } } }查看全部
-
使用内置函数操作数据库: SQLite DAtabase db=openOrCreatDatabase("stu.db,MODE_PRIVATE,null); db.execSQL("create table if not exists stutb(_id integer primary key autoincrement,neme text not null,age integer not null,sex text not null)"); ContentValues values=new ContentValues(); value.put("name","张三"); value.put("sex","男"); value.put("age","19"); long rowId =db.insert(table/"stutb",nullColumnHack/null,values);//多条数据 values.clear(); value.put("name","张三丰"); value.put("sex","男"); value.put("age","199"); values.clear(); valuesput("sex","女"); db.update(table/"stutb",values,whereClause/"id>?",whereArgs/new String{}{"3"});//将全部id>3的人sex改为女 db.delete("stutb","name like?",new String[]{"%丰%"});//删除所有名字中带有丰的人 Cursor c=db.query("stutb",null,"_id>?",new String[]{"0"},null,null,"name");//查询stutb下所有id>0的数据,按name排序 if(c!=null){ String[]columns=c.getColumnNames(); while(c.moveToNext()){ for(String columnName:columns){ log.i("info",c,getString(c.getColumnIndex(columnName))); } }c.close(); }db.close();查看全部
-
创建一个数据库并且打开: SQLite DAtabase db=openOrCreatDatabase("user.db,MODE_PRIVATE,null); db.execSQL("creat table if not exists usertb(_id integer primary key autoincrement,neme text not null,age integer not null,sex text not null)");//创建完成 db.execSQL("insert into usertb(name,sex,age)values('张三','女',18)");//插入数据(表格) Crusor c=db.rawQuery("select * from usertb",null); if(c!=null){ while(c.moveToNext()){ Log.i("info","_id:"+c.getInt(c.getColumnIndex("_id"))); Log.i("info","Log.i("info","name:"+c.getString(c.getColumnIndex("name"))); Log.i("info","age:"+c.getInt(c.getColumnIndex("age"))); Log.i("info","sex:"+c.getString(c.getColumnIndex("sex"))); Log.i("info",".......") //在log日志上输出数据,tag为"info" } c.close();//释放当前数据 }db.close();//释放整个数据库查看全部
-
存取用户名: public class MainActivity extends Activity{ EditText enUserName,etUserPass; CheckBox chk; SharePreferences pref; Editor editor; protected void onCreat(Bundle saveInstanceState){ super.onCreat(savedInstanceState); setContentView(R.layout.activity_main); //绑定对象view enUserName=(enUserName)findViewById(R.id.etuserName); etUserPass=(etUserPass)findViewById(R.id.etUserPass); chk=(CheckBox)findViewById(R.id.chkSaveName); pref=getSharePreferences("UserInfo",MODE_PRIVATE); editor=pref.edit();//启用编辑 } publi void doClick(View v){ switch(v.getId()){ case R.id.btnLogin: String name=etUserName.getText().toSting().trim(); String pass=etUserPass.getText().toSting().trim(); if("admin".equals(name)&&"123456"equals(pass)){ if(chk.isChecked()){ editor.putString("userName",name) editor.commit(); Toast.makeText(MainActivity.this,"登陆成功",Toast.LENGTH_LONG).show(); }else{ editor.remove("userName"); editor.commit(); }else{ Toast.makeText(MainActivity.this,"禁止登陆",Toast.LENGTH_LONG).show(); } }break; } } }查看全部
-
使用SharedPreferences存储数据: SharePreferences pref=getSharedPreferences("myPref",MODE_PRIVATE); Edit editor=pref.edit(); editor.putString/Int/Long/Boolean("key",value); editor.commit(); editor.remove("key"); editor.commit(); 附:System.currentTimeMillis()//获取当前系统时间。查看全部
-
cursor的作用查看全部
-
//每个程序都有自己的数据库 默认情况下是各自互相不干扰 //创建一个数据库 并且打开 SQLiteDatabase db = openOrCreateDatabase("user.db",//數據庫名稱 MODE_PRIVATE,//權限 null); db.execSQL("create table if not exists usertb (_id integer primary key autoincrement, name text not null , age integer not null , sex text not null )"); db.execSQL("insert into usertb(name,sex,age) values('张三','女',18)"); db.execSQL("insert into usertb(name,sex,age) values('李四','女',19)"); db.execSQL("insert into usertb(name,sex,age) values('王五','男',20)");查看全部
-
SQLiteDataBase的使用:查看全部
-
SQLiteDataBase的使用:查看全部
-
使用須知查看全部
-
SQLite數據類型:查看全部
-
事務處理的安全性查看全部
-
主要特點查看全部
-
SQLite介紹查看全部
举报
0/150
提交
取消