首页 > 代码库 > sql简单的语句
sql简单的语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ ---like的语法非常精妙,查资料!
String n=name.getText().toString(); String e=email.getText().toString(); //String add="insert into lgx_table(name,email) values(‘lgx‘,‘xxx‘)"; String add="insert into lgx_table(name,email) values(?,?)"; db.execSQL(add,new String[]{n,e});
android简单的数据库创建和使用
package com.example.dbdemo; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class DataBd extends SQLiteOpenHelper { public DataBd(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table lgx_table(_id integer primary key autoincrement,name varchar(20), email varchar(50))"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
package com.example.dbdemo; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { DataBd dataBd; SQLiteDatabase db; EditText name,email; TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dataBd = new DataBd(this, "lgx", null, 2); db = dataBd.getReadableDatabase(); name=(EditText) findViewById(R.id.name); email=(EditText) findViewById(R.id.email); text=(TextView) findViewById(R.id.text); } public void dbClick(View v) { switch (v.getId()) { case R.id.add: String n=name.getText().toString(); String e=email.getText().toString(); //String add="insert into lgx_table(name,email) values(‘lgx‘,‘xxx‘)"; String add="insert into lgx_table(name,email) values(?,?)"; db.execSQL(add,new String[]{n,e}); break; case R.id.delete: break; case R.id.update: break; case R.id.select: String select="select * from lgx_table "; //db.execSQL(select); Cursor cursor=db.rawQuery(select, null); while (cursor.moveToNext()) { String name=cursor.getString(cursor.getColumnIndex("name")); String email=cursor.getString(cursor.getColumnIndex("email")); text.setText(name+" "+email); } break; default: break; } } }
sql简单的语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。