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

android 如何打开s3db,Android开发教程:使用已有的SQL数据库极品好儿媳全文阅读,燃料乙醇放量,嘉兴办公家具,应向阳,58会展网,证书挂靠,鱼缸清洗,qq蜡笔小新头像我在sqliteadmin创建好数据库StuDB,里面的表如下:650)this.width=650;”>将创建好的数据库在DDMS中点击650)this.width=650;”>导入到data/data/程序的包名/650)this.width=650;”>SQLit…

大家好,又见面了,我是你们的朋友全栈君。

极品好儿媳全文阅读,燃料乙醇放量,嘉兴办公家具,应向阳,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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/136100.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号