Note that there are some explanatory texts on larger screens.

plurals
  1. POwhere to put the file from sqlitedatabase in our app
    primarykey
    data
    text
    <p>I created one app for database which contains a student table and 3 fields in it, but I don't know how to add the file in the app to the <code>sqlite database</code>.</p> <p><strong>database helper:</strong></p> <pre><code> public class DatabaseHelper extends SQLiteOpenHelper { public static final String DATA_BASE="Mydatabase.db"; public static final String TABLE_NAME="Student"; public static final int DATABASE_VERSION =1; public DatabaseHelper(Context context) { super(context, DATA_BASE, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_NAME + "(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } </code></pre> <hr> <p><strong>main activity:</strong></p> <pre><code>public class DatabaseHelper extends SQLiteOpenHelper { public static final String DATA_BASE="Mydatabase.db"; public static final String TABLE_NAME="Student"; public static final int DATABASE_VERSION =1; public DatabaseHelper(Context context) { super(context, DATA_BASE, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_NAME + "(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } </code></pre> <hr> <p><strong>display activity:</strong></p> <pre><code> public class DisplayActivity extends Activity { private ArrayList&lt;String&gt; arrayList = new ArrayList&lt;String&gt;(); private SQLiteDatabase Mydatabase; ListView listView; EditText enter; @Override public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.display); listView=(ListView)findViewById(R.id.listView); //OpenAndQueryDatabase try { DatabaseHelper db = new DatabaseHelper(this); //Open the database Mydatabase = db.getWritableDatabase(); Cursor c = Mydatabase.rawQuery( "SELECT * FROM Student", null); if (c != null ) { if (c.moveToFirst()) { do { String Name = c.getString( c.getColumnIndex("Name")); int age = c.getInt( c.getColumnIndex("AGE")); String address = c.getString( c.getColumnIndex("ADDRESS")); arrayList.add("Name : " + Name +"\n"+ "Age : " +age +"\n"+ "Address : " + address+"\n"); }while (c.moveToNext()); } } } catch (SQLiteException se ) { } finally { if (Mydatabase != null) Mydatabase.close(); } //displayResultList listView.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, arrayList)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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