Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite DB not created
    text
    copied!<p>This code is not creating my database. I wanted to create a pre-populated table with some default values on creation of the table. Although no error while execution. Any help?</p> <p>DatabaseHelper Code:</p> <pre><code>public class DatabaseHelper extends SQLiteOpenHelper { public static String dbName = "whatever.db"; public static int dbVersion = 2; public DatabaseHelper(Context context) { super(context, dbName, null, dbVersion); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub String createTable = "CREATE TABLE smart (UID INTEGER PRIMARY KEY, NAME TEXT);"; db.execSQL(createTable); ContentValues cv = new ContentValues(); cv.put("UID", 9); cv.put("NAME", "clear"); db.insert("smart", null, cv); db.close(); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS smart"); } } </code></pre> <p>MainActivity code:</p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DatabaseHelper dbHelper = new DatabaseHelper(this); dbHelper.close(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </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