从SQLite数据库中获取数据?

时间:2014-06-04 11:23:23

标签: android database sqlite

我想从SQLite中获取我的注册用户数据,而不是我的Android应用程序中的Web服务器。我希望当我的应用程序的注册用户使用他们的Id和密码登录时。然后应该获取与应用程序相关的现有数据。请指导我如何做到这一点。  我创建了两个Java文件,因为我创建了SQLite数据库并在其中插入值。

Login.Java

登录页面,注册用户使用自己的帐号和密码登录应用程序。只有注册用户才能登录。我在我的应用程序中使用了Json解析概念来解析和交换我的数据与Web服务。

Password.java     以下是Database类的内容

           I t is the second class which include the connectivity part for log in page

            public class PasswordDB

            {
                EditText edittext;
                 TextView tv;
                private static final  String DATABASE_NAME = "DGC.db";
                private static final int DATABASE_VERSION = 1;
                static final String TABLE_NAME = "Drivers";
                private static Context context;
                static SQLiteDatabase db;

                private SQLiteStatement insertStmt;

               //insertion of the value into table//
                private static final String INSERT = "insert into " + TABLE_NAME + " (mfname,msname,mun,mstreet,msuburb,mstate,mpostcode,mlicense,mid,mmobile,memail,mimagelicense,mauthcard,mpic) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                protected static final String enternpw = null;
                public PasswordDB(Context context) {
                PasswordDB.context = context;
                OpenHelper openHelper = new OpenHelper(PasswordDB.context);
                PasswordDB.db = openHelper.getWritableDatabase();
                this.insertStmt = PasswordDB.db.compileStatement(INSERT);
                }

                public long insert(String mfname,String msname,String mun,String mstreet,String msuburb,String mstate,String mpostcode,String mlicense,String mid,String mmobile,String memail,byte[] mimagelicense,byte[] mauthcard,byte[] mpic ) {
                this.insertStmt.bindString(1, mfname);
                this.insertStmt.bindString(2, msname);
                this.insertStmt.bindString(3, mun);
                this.insertStmt.bindString(4, mstreet);
                this.insertStmt.bindString(5, msuburb);
                this.insertStmt.bindString(6, mstate);
             //   this.insertStmt.bindString(7, mpassword);
                this.insertStmt.bindString(7, mpostcode);
                this.insertStmt.bindString(8, mlicense);
                this.insertStmt.bindString(9, mid);
                this.insertStmt.bindString(10, mmobile);
                this.insertStmt.bindString(11, memail);
                this.insertStmt.bindBlob(12, mimagelicense);
                this.insertStmt.bindBlob(13, mauthcard);
                this.insertStmt.bindBlob(14, mpic);
                return this.insertStmt.executeInsert();
                }


                public void deleteAll() {
                db.delete(TABLE_NAME, null, null);
                }

                public List<String[]> selectAll()
                {
                List<String[]> list = new ArrayList<String[]>();
                Cursor cursor = db.query(TABLE_NAME, new String[] { "id","mfname","msname","mun","mstreet","msuburb","mstate","mpassword","mconfirm_password","mpostcode","mlicense","mid","mmobile","memail","mimagelicense","mauthcard","mpic" }, null, null, null, null, "memail asc");
                int x=0;
                if (cursor.moveToFirst()) {
                   do {
                    String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2),
                            cursor.getString(3),cursor.getString(4),cursor.getString(5),
                            cursor.getString(6),cursor.getString(7),cursor.getString(8),cursor.getString(9),cursor.getString(10),cursor.getString(11),cursor.getString(12),cursor.getString(13),cursor.getString(14),cursor.getString(15)};
                    list.add(b1);
                    x=x+1;
                   } while (cursor.moveToNext());
                }
                if (cursor != null && !cursor.isClosed()) {
                   cursor.close();
                }
                cursor.close();
                return list;
               }





             //method to delete the value from table//
               public void delete(int rowId) {
                db.delete(TABLE_NAME, null, null);
               }

               private static class OpenHelper extends SQLiteOpenHelper {
                OpenHelper(Context context) {
                     super(context, DATABASE_NAME, null, DATABASE_VERSION);
                }
                @Override
                public void onCreate(SQLiteDatabase db) {
                     db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY, mfname TEXT, msname TEXT,mun TEXT,mstreet TEXT,msuburb TEXT,mstate TEXT,mpassword TEXT,mconfirm_password TEXT,mpostcode TEXT,mlicense TEXT,mid TEXT,mmobile TEXT,memail TEXT,mimagelicense BLOB,mauthcard BLOB,mpic BLOB)");
                }

                @Override
                public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
                    {
                     db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
                     onCreate(db);
                }
               }
            //Database Fetching//
               public ArrayList getAllDriversDetail()
               {
                   Cursor resultSet = db.rawQuery("Select * from TutorialsPoint",null);
                   resultSet.moveToFirst();
                   String username = resultSet.getString(1);
                   String password = resultSet.getString(2);
                return null;
               }

            private SQLiteDatabase getReadableDatabase() {
                // TODO Auto-generated method stub
                return null;
            }

            public Cursor rawQuery(String selectQuery, Object object) {
                // TODO Auto-generated method stub
                return null;
            }
            public static PasswordDB getDBAdapterInstance(ViewData viewPassword) {
                // TODO Auto-generated method stub
                return null;
            }
            public Object getenternpw() {
                // TODO Auto-generated method stub
                return null;
            }
            public static Cursor getSinlgeEntry() {
                // TODO Auto-generated method stub

                Cursor cur =db.rawQuery("SELECT * FROM "+  TABLE_NAME, null);
                // colName1+"='"+name+"'" ->  wherclause
                System.out.println("Record count are "+cur.getCount());
                return cur; 

            }

            public static void close() {
                // TODO Auto-generated method stub

            }
            public PasswordDB open() {
                // TODO Auto-generated method stub
                return null;
            }


            }

0 个答案:

没有答案