|
PackageCom.Zhizhao.androidtraining. Save_data import android.content.contentvalues; import android.content.context ; import android.database.cursor ; import android.database.sqlite.sqlitedatabase; import android.util.log ;
/**
* Created by Zhizhao on 2015/11/2 0002 in 10:53.
* Ps: This class is written in the end and I think I can't go on like this. So go on and just add some Android basic operation to use * and I am more inclined to improve my project experience faster. * in terms of project experience, there's nothing more obvious than actually doing a project upgrade yourself. * so next, learn the open source project and publish it. * the project will continue to be written and submitted. Blog will also continue to follow up. */ public classUsingdatabase{ PrivateString DbName; PrivateString TableName; PrivateContext DbContext; PrivateString UserName; PrivateString UserPassword;
PublicUsingdatabase(StringDbName,StringTableName, ContextContext,StringData1,StringData2){ This.DbName=DbName; This.TableName=TableName; this. DbContext = context this. UserName = data1 this. UserPassword = data2}
public void createusertable () { //openorcreatedatabase (String name, int mode, Cursorfactory factory);
// The first parameter is the database name, the second is a permission, and the third iscursorfactoryobjects, // returns when used for queriesCursorthe child class object. or incomingNULLUse the defaultFactoryConstruction SqlitedatabaseDb=DbContext.Openorcreatedatabase(DbName,DbContext.Mode_private,Null); StringCmd="CREATE TABLE IF not EXISTS"+TableName+"(name varchar, password varchar)"; Db.Execsql(cmd);
contentvalues CV = Span style= "COLOR: #93c763" >new contentvalues (); cv. Put ( "name" , username); cv. Put ( "password" , userpassword); // This is killing me. Remember, it is the name of the table. Db.Insert(TableName,Null,Cv); Db.Close();
}
public voidInsertusertable(){ SqlitedatabaseDb=DbContext.Openorcreatedatabase(DbName,DbContext.mode_privatenull
}
public void queryusertable () { sqlitedatabase db = dbcontext. Openorcreatedatabase (dbname dbcontext.mode_private, null // the results of the query are passedCursorreturn. cursors that represent datasets cursor cursor = db. Rawquery("select * from"+tableName, null); Log. V(" Results of database queries===", "----------"); While(cursor. MoveToNext()) { //query based on the column sequence of the database table. String str = cursor. GetString(0); Log. V(" Results of database queries= = = ", " "+str);
}
Log. V(" Results of database queries===", "+++"); Cursor. Close(); DB. Close();
}
} |