package com.ljy;import android.R.integer;
import android.R.string;
import android.app.Activity;
import android.content.ContentValues;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;public class mainActivity extends Activity {
/** Called when the activity is first created. */
SQLiteDatabase db = null;
String dbnameString = "ljy.db";
String tablenameString = "table1";
String id="_id";
String name = "Name";
String sex = "SEX";
Button bt1,bt2,bt3,bt4;
TextView tv1,tv2,tv3,tv4;
String creatTable = "CREATE TABLE"+tablenameString+"("+id+"INRERGER PRIMARY KEY"+","
+name+"TEXT"+","+sex+"INTERGER)";
int i=0;
protected String tag="AAA";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt1=(Button)findViewById(R.id.bt1);
bt2=(Button)findViewById(R.id.bt2);
bt3=(Button)findViewById(R.id.bt3);
bt4=(Button)findViewById(R.id.bt4);
tv1=(TextView)findViewById(R.id.tv1);
tv2=(TextView)findViewById(R.id.tv2);
tv3=(TextView)findViewById(R.id.tv3);
tv4=(TextView)findViewById(R.id.tv4);
db=this.openOrCreateDatabase(dbnameString, MODE_PRIVATE, null);
try{
db.execSQL(creatTable);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(name, "罗建英");
cv.put(sex, 23);
db.insert(tablenameString, null, cv);
i++;
tv1.setText("插入成功"+i);
Log.v(tag, "1");
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
String delete = "DELETE FROM"+tablenameString+"WHERE _id =1";
try{
db.execSQL(delete);
tv2.setText("删除第一项");//+num);
}catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
bt3.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(name, "熙熙");
cv.put(sex, 23);
int num=db.update(tablenameString, cv, name+"=?", new String[]{"罗建英"});
tv3.setText("更新第三项"+num);
}
});
bt4.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
String select = "SELECT FROM"+tablenameString+"WHERE _id = 5";
try{
db.execSQL(select);
tv4.setText("查找第五项");
Log.v(tag, "42");
}catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
}
}
import android.R.string;
import android.app.Activity;
import android.content.ContentValues;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;public class mainActivity extends Activity {
/** Called when the activity is first created. */
SQLiteDatabase db = null;
String dbnameString = "ljy.db";
String tablenameString = "table1";
String id="_id";
String name = "Name";
String sex = "SEX";
Button bt1,bt2,bt3,bt4;
TextView tv1,tv2,tv3,tv4;
String creatTable = "CREATE TABLE"+tablenameString+"("+id+"INRERGER PRIMARY KEY"+","
+name+"TEXT"+","+sex+"INTERGER)";
int i=0;
protected String tag="AAA";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt1=(Button)findViewById(R.id.bt1);
bt2=(Button)findViewById(R.id.bt2);
bt3=(Button)findViewById(R.id.bt3);
bt4=(Button)findViewById(R.id.bt4);
tv1=(TextView)findViewById(R.id.tv1);
tv2=(TextView)findViewById(R.id.tv2);
tv3=(TextView)findViewById(R.id.tv3);
tv4=(TextView)findViewById(R.id.tv4);
db=this.openOrCreateDatabase(dbnameString, MODE_PRIVATE, null);
try{
db.execSQL(creatTable);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(name, "罗建英");
cv.put(sex, 23);
db.insert(tablenameString, null, cv);
i++;
tv1.setText("插入成功"+i);
Log.v(tag, "1");
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
String delete = "DELETE FROM"+tablenameString+"WHERE _id =1";
try{
db.execSQL(delete);
tv2.setText("删除第一项");//+num);
}catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
bt3.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(name, "熙熙");
cv.put(sex, 23);
int num=db.update(tablenameString, cv, name+"=?", new String[]{"罗建英"});
tv3.setText("更新第三项"+num);
}
});
bt4.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
String select = "SELECT FROM"+tablenameString+"WHERE _id = 5";
try{
db.execSQL(select);
tv4.setText("查找第五项");
Log.v(tag, "42");
}catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
}
}
解决方案 »
- 既然service跟Ui线程在同一个线程,那为什么在service播放音乐的时候不会阻塞UI线程呢
- adt20 建立Android工程的时候报错 No Launcher activity found
- 怎么改变LocationListener的监听时间?
- 关于3.0版本的android.graphics.Canvas.getGL没有了的问题
- 针对竖屏开发UI,需要哪些必要的步骤?或者预置条件
- 急!Android图片保存的问题
- android放大效果
- 请问个手机远程控制智能家居的问题
- 类似汽车之家这样的对比车型可以左右滑动效果怎么实现的
- 在Fragment中跳转Activity
- android .txt文件的读取编码格式问题
- 蓝牙传输问题
还请去看看sql语句和sqlite数据操作吧!
还请去看看sql语句和sqlite数据操作吧!