想在sqllite数据库中硬编码数据

时间:2015-09-06 21:27:01

标签: database sqlite

我想在我的表格中硬编码数据,请指导我 在我的应用程序中有登录名和密码字段我想硬编码 我创建了一个databasehandler1类,其中我创建了一个数据库,现在我要输入1个值,如用户名" ebad"密码" abc"对不起,我的英语不好 这是我的班级

package com.example.ahmed.vehiclepermitapp;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class DatabaseHandler1 extends SQLiteOpenHelper
{
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME ="contact1.db";
    private static final String TABLE_NAME ="users";
    private static final String COLUMN_ID ="id";
    private static final String COLUMN_ADMIN ="admin";
    private static final String COLUMN_PASSWORD ="password";
    SQLiteDatabase da;
    private static final String TABLE_CREATE ="create table users (id integer primary key not null  , " + "admin text not null , password not null);";

    public DatabaseHandler1(Context context){
        super(context , DATABASE_NAME , null , DATABASE_VERSION);
    }

@Override
public void onCreate(SQLiteDatabase da)
    {
        da.execSQL(TABLE_CREATE);
        this.da=da;


    }

    public String searchPass(String admin)
    {
        da = this.getReadableDatabase();
        String query = "select admin , pass from "+TABLE_NAME;
        Cursor cursor= da.rawQuery(query,null);
        String a,b;
        b= "Not found";
        if (cursor.moveToFirst())
        {
            do{
                a= cursor.getString(0);
                if (a.equals(admin)){
                    b= cursor.getString(1);
                    break;

                }

            }
            while(cursor.moveToNext());
        }
        return b;


    }

@Override
public void onUpgrade(SQLiteDatabase da, int i, int i2)
    {
        String query = "DROP TABLE IF EXISTS "+TABLE_NAME;
        da.execSQL(query);
        this.onCreate(da);


    }
}

0 个答案:

没有答案