Note that there are some explanatory texts on larger screens.

plurals
  1. POImporting Database from Local to Emulator & vice versa for SQLite (Eclipse)
    primarykey
    data
    text
    <p>I am developing an android project (Eclipse java - Emulator 5554 - SQLite). </p> <p>But I don't know how to import or export databases. Please look at the code below first</p> <p>code segment 1: (this code segment is in onClick method of a button in android device)</p> <pre><code> public void onClick(View v) { SQLiteDatabase db = openOrCreateDatabase("EOS_DB_TRY_OUT", SQLiteDatabase.CREATE_IF_NECESSARY, null); DatabaseConnector dbConnector = new DatabaseConnector(getBaseContext(), DB_NAME, null,1); dbConnector.onCreate(db); // private static String DB_PATH = "assets/database/eosdatabase.zip"; //private static String DB_NAME = "eosdatabase.db"; these are global variables in //class... } </code></pre> <p>Code segment 2: This is another class in which I am trying to create(or use existing one if it exists) and connect</p> <pre><code>public class DatabaseConnector extends SQLiteOpenHelper { public DatabaseConnector(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { System.out.println("On create works"); try { db.execSQL("DROP TABLE IF EXISTS actuator;"); db.execSQL("CREATE TABLE IF NOT EXISTS actuator ("+ "ACTUATOR_ID INT NOT NULL,"+ "ACTUATOR_HW_ID int(11) DEFAULT NULL,"+ "DEVICE_NAME TEXT(45) DEFAULT NULL,"+ "DEVICE_TYPE TEXT(45) DEFAULT NULL,"+ "DEVICE_SUB_TYPE TEXT(45) DEFAULT NULL,"+ "LOCATION_ID INT(11) DEFAULT NULL,"+ "STATUES_VALUE REAL DEFAULT NULL,"+ "MAX_STATUES_VALUE REAL DEFAULT NULL,"+ "MIN_STATUES_VALUE REAL DEFAULT NULL,"+ "PRIMARY KEY (`ACTUATOR_ID`))"); System.out.println("table created now values will be added"); } catch (SQLException e) { System.out.println("table is not created"); } try { db.execSQL("INSERT INTO actuator (ACTUATOR_ID, ACTUATOR_HW_ID, DEVICE_NAME, DEVICE_TYPE, DEVICE_SUB_TYPE, LOCATION_ID, STATUES_VALUE, MAX_STATUES_VALUE, MIN_STATUES_VALUE) " + "VALUES (4,2, 'Heat Sensor FX615','Heat Sensor', 'Optic Heat Sensor', 4, 6, 7, 8) " ); System.out.println("values are added"); } catch (SQLiteException e) { e.printStackTrace(); System.out.println("values are not added"); } try { Cursor c = db.rawQuery("SELECT LOCATION_ID FROM actuator WHERE ACTUATOR_ID = 4", null); if (c != null &amp;&amp; c.moveToFirst()) { String berkay = c.getString(0); System.out.println(berkay); } System.out.println("select finished"); } catch (SQLiteException e) { e.printStackTrace(); System.out.println("not selected"); } </code></pre> <p>The thing is:</p> <p>The code is working, syntax is right but I was working on it yesterday without any external database and code was creating new database when executing and deleting it after execution because I was just testing syntax. Now code is working well but I don't know which database the code is using.</p> <p>Today I am making a database via sqliteadmin database browser and I want to use it in emulator (not creating new database and deleting it for every execution, I want permanent database). I don't understand this code, Is this code creating new one and deleting it like what I did before ? If so, how can I import the external database and use it?</p> <p>note : the name of database which I want to use is "eosdatabase" and the location of it desktop/databasefolder/database/eosdatabase.zip/eosdatabase.s3db</p> <p>note2: after importing external database into emulator database file, how can i connect that database (if you solve my code problem i would be happy not only importing database into emulator, I need code instead of the one above)</p>
    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.
    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