android 如何打开s3db,Android开发教程:使用已有的SQL数据库

极品好儿媳全文阅读,燃料乙醇放量,嘉兴办公家具,应向阳,58会展网,证书挂靠,鱼缸清洗,qq蜡笔小新头像

我在sqliteadmin 创建好数据库StuDB,里面的表如下:

4306c2f8ffc0d314574e1b5b5c60268d.png650) this.width=650;">

将创建好的数据库在DDMS中点击

4952a50f697799fca14354ecb05e8b94.png650) this.width=650;">导入到data/data/程序的包名/

1d1d2c3b5c33e4ef19e9578437e9222b.png650) this.width=650;">

SQLiteTestActivity.java

package com.lingdududu.test;  import Android.app.Activity;  import android.database.Cursor;  import android.database.sqlite.SQLiteDatabase;  import android.os.Bundle;  import android.view.View;  import android.view.View.OnClickListener;  import android.widget.Button;  import android.widget.EditText;  import android.widget.Toast;  public class SQLiteTestActivity extends Activity {  /** Called when the activity is first created. */ private EditText studentText;  private EditText teacherText;  private Button queryBtn;  SQLiteDatabase stuDb;    @Override public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);    studentText = (EditText)findViewById(R.id.stu_name);  teacherText = (EditText)findViewById(R.id.teacher_name);  queryBtn = (Button)findViewById(R.id.query);      queryBtn.setOnClickListener(new queryListener());   }  class queryListener implements OnClickListener{  @Override public void onClick(View v) {  //调用查询方法  query(); stuDb.close();   }   }  //查询方法  private void query() {  //打开或者创建数据库  stuDb = SQLiteDatabase.openOrCreateDatabase("data/data/com.lingdududu.test/StuDB.s3db", null);  try {    String string =studentText.getText().toString();   String sql = "Select sname from Student where snumber="+string;  Cursor cursor = stuDb.rawQuery(sql,null);  cursor.moveToFirst();   teacherText.setText(cursor.getString(cursor.getColumnIndex("sname")));  } catch (Exception e) {  Toast.makeText(this, "请检查输入的学生学号是否正确", Toast.LENGTH_LONG).show();  }   }   }

main.xml

?xml version="1.0" encoding="utf-8"?   LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"    TextView   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="@string/input_name" /   EditText   android:id="@+id/stu_name" android:layout_width="fill_parent"   android:layout_height="wrap_content"   /   Button   android:id="@+id/query" android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="开始查询" /   TextView   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="@string/teacher_name" /     EditText   android:id="@+id/teacher_name" android:layout_width="fill_parent"   android:layout_height="wrap_content" android:editable="false"   /   /LinearLayout

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值