Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>Try this DatabaseUtil class to create : public class DatabaseUtil { private static final String DATABASE_NAME = "database_name"; private static final int DATABASE_VERSION = 1; private static final String TABLE_NAME = "table_name"; private static final String ROW_ID = "_id"; private static final String PARAM1 = "param1"; private static final String PARAM2 = "param2"; private static final String CREATE_TABLE = "create table " + TABLE_NAME + " (" + ROW_ID + " integer primary key autoincrement, "`enter code here` + param1+" text not null, " + param2+ " text not null);"; private final Context context; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) {super(context, DATABASE_NAME, null, DATABASE_VERSION);} @Override public void onCreate(SQLiteDatabase db) {db.execSQL(CREATE_TABLE);} @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {} } public DatabaseUtil(Context c) {this.context = c;} public DatabaseUtil open() throws SQLException { mDbHelper = new DatabaseHelper(context); mDb = mDbHelper.getWritableDatabase(); return this; } public void close() {mDbHelper.close();} public long add(String strparam1,String strparam2) { ContentValues cv = new ContentValues(); cv.put(PARAM1 ,strparam1); cv.put(PARAM2 ,strparam2); return mDb.insert(TABLE_NAME, null, cv); } public Cursor fetchAll() {return mDb.query(TABLE_NAME,new String[] {ROW_ID, PARAM1, PARAM2},null,null,null,null,null);} public boolean deleteTitle(String strparam1) {return mDb.delete(TABLE_NAME,PARAM1 + "='" + strparam1+"'", null)&gt;0;} } Then to create and add the values, DatabaseUtil util = new DatabaseUtil(this); util.open(); util.add(param1, param2); util.close(); This will be simpler insert for you. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload