您现在的位置是:主页 > news > 深圳外贸网站公司/百度账号是什么

深圳外贸网站公司/百度账号是什么

admin2025/6/27 8:59:49news

简介深圳外贸网站公司,百度账号是什么,成都响应式网站建设,wordpress修改标签页目录一、sqlite数据库二、在Android中使用sqlite3一、sqlite数据库 优点:占用资源少、运行效率高、安全可靠、可移植性强 使用sqlite3 2.1 开启夜神模拟器并连接(连接不成功会报错) 2.2 找到模拟器的根目录 2.3 在夜神模拟器的bin地址栏开启…

深圳外贸网站公司,百度账号是什么,成都响应式网站建设,wordpress修改标签页目录一、sqlite数据库二、在Android中使用sqlite3一、sqlite数据库 优点:占用资源少、运行效率高、安全可靠、可移植性强 使用sqlite3 2.1 开启夜神模拟器并连接(连接不成功会报错) 2.2 找到模拟器的根目录 2.3 在夜神模拟器的bin地址栏开启…

目录

          • 一、sqlite数据库
          • 二、在Android中使用sqlite3

一、sqlite数据库
  1. 优点:占用资源少、运行效率高、安全可靠、可移植性强

  2. 使用sqlite3

    2.1 开启夜神模拟器并连接(连接不成功会报错)

    2.2 找到模拟器的根目录

    2.3 在夜神模拟器的bin地址栏开启cmd

    2.4 写入命令 adb shell,会进入一个有#的就成功了

    2.5 运行文件到虚拟设备,然后通过file explorer去找到包名称

    2.6 我们一般会把sqlite文件放到个固定文件夹中,所以我们需要建一个目录mkdir /data/data/com.example.save_sqlite/database(mkdir是创建文件夹的命令,database是创建文件夹的名字)

    2.7 adb shell

    2.8 切换到对应的目录下 cd /data/data/com.example.save_sqlite/database(如果写错了可以用 .exit来撤销上一步的命令)

    2.9 使用sqlite3 创建或者打开数据库:sqlite3 数据库名(若数据库存在则打开,若不存在则创建并打开)
    如:sqlite3 mysqlite 出现sqlite>就成功了

    2.10 创建一个表(此处写命令,建议在记事本或者word中写后复制)
    如:
    create table tb_user(
    id integer primary key autoincrement,
    name varchar(50) not null,
    password varchar(20) not null
    );

    2.11 查看数据表格 .table

    2.12 插入(增加)一条数据
    insert into tb_user values(null,“zhangsan”,“zhangsan123”);

    2.13 查询数据
    select * from tb_user;

    2.14 .schema可以显示出创建表格时的代码

    	数据库具体语句的语法:创建表:create table 表名(列名称1 类型1 约束1, 列名称2 类型2 约束2);删除表:drop table 表名称;更改表结构:增加一个列:alter table 表名称 add column 字段名 数据类型 约束;(约束一般为 not null一类的)插入数据:insert into 表名称 values(value1,value2,value3,value4);//此处value个数与列名称(表属性)个数一致删除数据:delete from 表名称 where 条件;更新数据:update 表名称 set 字段="要修改成什么的值" where 条件;查询数据:查询所有:select * from 表名称;携带条件:select 字段1,字段n from 表名称 where 条件;整体:找到数据库文件并打开
    
二、在Android中使用sqlite3
  1. 在src文件夹内,新建一个class类文件,如:MyDBOpenHelper.java
    		public class MyDBOpenHelper extends SQLiteOpenHelper{public MyDBOpenHelper(Context context, String name, CursorFactory factory,int version) {super(context, "my.db", null, 1);//super(context, name, factory, version);分别为继承父类的:文本、数据库名字、模式、版本}public void onCreate(SQLiteDatabase db) {//数据库第一次被创建时调用//在此处创建数据表,因为数据库对象db是可以直接执行sql语句的db.execSQL("create table person(personid integer primary key autoincrement,name varchar(50))");}public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {//当数据库版本改变时执行S//此处增加一个字段db.execSQL("alter table person addcolumn phone varchar(15);");}}
    
  2. 在主Java中
    		public class MainActivity extends Activity implements View.OnClickListener{Button btn_insert;Button btn_delete;Button btn_update;Button btn_query;private SQLiteDatabase db;//数据库对象,可以执行sql语句,操作数据库private MyDBOpenHelper myDBHelper;//创建数据库时定义的变量private int i=1;//用在插入中private StringBuilder sb;//用来构建查询中的最后的where条件@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);myDBHelper=new MyDBOpenHelper(MainActivity.this, "my.db", null, 1); //在Activity创建时,实例化数据库对象btn_insert=(Button)findViewById(R.id.insert);btn_delete=(Button)findViewById(R.id.delete);btn_update=(Button)findViewById(R.id.update);btn_query=(Button)findViewById(R.id.query);btn_insert.setOnClickListener(this);btn_delete.setOnClickListener(this);btn_update.setOnClickListener(this);btn_query.setOnClickListener(this);}public void onClick(View v) {//v为每一个视图db=myDBHelper.getWritableDatabase();switch (v.getId()) {case R.id.insert: ContentValues value1=new ContentValues();//ContentValues对象,时一种(key.value)的数据,相当于Python中的字典value1.put("name", "君山"+i+"品");i++;db.insert("person", null, value1);Toast.makeText(getApplicationContext(), "信息增加结束", 1).show();break;case R.id.delete: db.delete("person", "personid=2", null);//db.delete("person", "personid=?", new String[]{"3"});//这里使用了占位符break;case R.id.update:ContentValues value2=new ContentValues();value2.put("name", "君山1000品");db.update("person", value2, "personid=1", null);break;case R.id.query:sb=new StringBuilder();//构建字符串用Cursor cursor=db.query("person", null, null, null, null, null, null);//游标查询(借助游标移动查询)if(cursor.moveToFirst()){do{int id=cursor.getInt(cursor.getColumnIndex("personid"));String name=cursor.getString(cursor.getColumnIndex("name"));sb.append("id:"+id+"\tname:"+name+"\n");//把id和name拼接起来放入sb}while(cursor.moveToNext());}cursor.close();TextView showTextView=(TextView)findViewById(R.id.showtext);showTextView.setText(sb.toString());//把内容提取到文本框中去break;default: break;}}}