欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何使用占位符對數(shù)據(jù)庫進(jìn)行操作

這篇文章將為大家詳細(xì)講解有關(guān)如何使用占位符對數(shù)據(jù)庫進(jìn)行操作,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元巫溪做網(wǎng)站,已為上家服務(wù),為巫溪各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792

效果圖

 如何使用占位符對數(shù)據(jù)庫進(jìn)行操作

在main.xml中:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    android:gravity="center_horizontal">

    <Button

        android:id="@+id/insertBut"

        android:layout_marginTop="8dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="增加數(shù)據(jù)" />

    <Button

        android:id="@+id/updateBut"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="修改數(shù)據(jù)" />

    <Button

        android:id="@+id/deleteBut"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="刪除數(shù)據(jù)" />

</LinearLayout>

創(chuàng)建數(shù)據(jù)庫的建表操作類Mytab.java

package com.li.sqlite;

import android.database.sqlite.SQLiteDatabase;

public class Mytab {

  private static final String TABLENAME = "mytab"; // 表示要操作的數(shù)據(jù)表名稱

  private SQLiteDatabase db = null; // 數(shù)據(jù)庫操作

  public Mytab(SQLiteDatabase db) { 

     this.db = db;

  }

  public void insert(String name,String birthday) {  //向表中增加數(shù)據(jù)

     String sql = "INSERT INTO " + TABLENAME + "(name,birthday) VALUES (?,?)";

     Object args[] = new Object[]{name,birthday};

     this.db.execSQL(sql,args) ;

     this.db.close() ;

  }

  public void update(int id, String name, String birthday) {  //修改表的數(shù)據(jù)

     String sql = "UPDATE " + TABLENAME + " SET name=?,birthday=? WHERE id=?";

     Object args[] = new Object[]{name,birthday,id};

     this.db.execSQL(sql,args);

     this.db.close() ;

  }

  public void delete(int id) {     //刪除表的數(shù)據(jù)

     String sql = "DELETE FROM " + TABLENAME + " WHERE id=?";

     Object args[] = new Object[]{id};

     this.db.execSQL(sql,args) ;

     this.db.close() ;

  }

}

在MySQLiteDemo.java中:

package com.li.sqlite;

import android.app.Activity;

import android.database.sqlite.SQLiteOpenHelper;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MySQLiteDemo extends Activity {

  private Button inserBut = null;

  private Button updateBut = null;

  private Button deleteBut = null;

  private SQLiteOpenHelper helper = null;

  private Mytab mtab = null;

  private static int count = 0;

  @Override

  public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);

     super.setContentView(R.layout.main);

     this.inserBut = (Button)super.findViewById(R.id.insertBut);

     this.updateBut = (Button)super.findViewById(R.id.updateBut);

     this.deleteBut = (Button)super.findViewById(R.id.deleteBut);

     this.helper = new MyDatabaseHelper(this);

     this.inserBut.setOnClickListener(new InertOnClickListenerImpl());

     this.updateBut.setOnClickListener(new UpdateOnClickListenerImpl());

     this.deleteBut.setOnClickListener(new DeleteOnClickListenerImpl());

  }

  private class InertOnClickListenerImpl implements OnClickListener{

     public void onClick(View v) {

       MySQLiteDemo.this.mtab = new Mytab(

            MySQLiteDemo.this.helper.getWritableDatabase());

       MySQLiteDemo.this.mtab.insert("liyewen" + count++, "1988-08-16");

     }

  }

  private class UpdateOnClickListenerImpl implements OnClickListener{

     public void onClick(View v) {

       MySQLiteDemo.this.mtab = new Mytab(

            MySQLiteDemo.this.helper.getWritableDatabase());

       MySQLiteDemo.this.mtab.update(30, "update", "1988/8/15");

     }

  }

  private class DeleteOnClickListenerImpl implements OnClickListener{

     public void onClick(View v) {

       MySQLiteDemo.this.mtab = new Mytab(

            MySQLiteDemo.this.helper.getWritableDatabase());

       MySQLiteDemo.this.mtab.delete(31);

     }

  }

}

關(guān)于“如何使用占位符對數(shù)據(jù)庫進(jìn)行操作”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。

本文題目:如何使用占位符對數(shù)據(jù)庫進(jìn)行操作
轉(zhuǎn)載注明:http://chinadenli.net/article10/gisigo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、App開發(fā)面包屑導(dǎo)航、網(wǎng)站營銷網(wǎng)站改版、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作