0

here is my code for selecting something from the table SqliteTmp:

 Cursor c=null;
                    DataBaseHelper myDbHelper = new DataBaseHelper(StaffActivity.this);
                    try {
                        myDbHelper.createDataBase();
                    } catch (IOException ioe) {
                        throw new Error("Unable to create database");
                    }
                    try {
                        myDbHelper.openDataBase();

                    }catch(SQLException sqle){

                        throw sqle;
                    }
                    Toast.makeText(StaffActivity.this, "Success", Toast.LENGTH_SHORT).show();
                    c=myDbHelper.query("SqliteTmp", null, null, null, null,null, null);
                    if(c.moveToFirst())
                    {
                        do {

                            Toast.makeText(StaffActivity.this,
                                    "_id: " + c.getString(0) + "\n",  
                                    Toast.LENGTH_LONG).show();
                        } while (c.moveToNext());
                    }
                }

Logcat says this:

android.database.sqlite.SQLiteException: no such table: SqliteTmp (code 1): , while compiling: SELECT * FROM SqliteTmp

but the SqlTmp.db shows that:

CREATE TABLE `SqliteTmp` (
    `_id`   int(11) NOT NULL,
    `ean`   varchar(12) NOT NULL,
    `bezeichnung`   varchar(100) NOT NULL,
    `art`   varchar(1),
    `stammkost` varchar(4),
    `marker`    varchar(1),
    PRIMARY KEY(_id)
);

Why the SqliteTmp table isn't found? Its really in it.

Piet
  • 395
  • 2
  • 7
  • 17
  • Please have a look at my answer. It might have similar issue with your table creation http://stackoverflow.com/questions/29986355/android-sqlite-insert-not-inserting/29987400#29987400 – Jibran Khan May 25 '15 at 17:34

2 Answers2

1

I think i have got the same problem. Please make sure you have diffrent database name for each table. This will surly solve your problem.

0

Make sure that your database path and file name are correct. Depending on your code, it is probably creating a blank database instead of opening yours.

Joel Fazio
  • 172
  • 8
  • I changed from DB_PATH="/data/data/"+context.getPackageName()+"/"+"databases/"; to DB_PATH="/Android/data/eu.straff/files/databases/"; and now Logcat: 05-25 19:44:33.722 18252-18252/eu.straff E/SQLiteDatabase﹕ Failed to open database '/Android/data/eu.straff/files/databases/SqliteTmp.db'. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database – Piet May 25 '15 at 17:45
  • `05-25 19:51:06.212 22712-22712/eu.straff E/SQLiteLog﹕ (14) cannot open file at line 30192 of [00bb9c9ce4] 05-25 19:51:06.212 22712-22712/eu.straff E/SQLiteLog﹕ (14) os_unix.c:30192: (2) open(/storage/emulated/0/Android/data/eu.straff/files/databases/SqliteTmp.dbSqliteTmp.db) - 05-25 19:51:06.232 22712-22712/eu.straff E/SQLiteDatabase﹕ Failed to open database '/storage/emulated/0/Android/data/eu.straff/files/databases/SqliteTmp.dbSqliteTmp.db'. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database` – Piet May 25 '15 at 17:51
  • Are you opening a pre-existing database, or creating one in your app? If you open an existing database, you have to copy it from your assets folder into a new database instead of just trying to open it. – Joel Fazio May 25 '15 at 17:53
  • I reopen a previous one (downloaded from my server to /Android/data/eu.straff/files/databases/. I dont have one in my assets folder. – Piet May 25 '15 at 17:57
  • Try adding it to your assets folder then copy it to data/data/your package/databases then open it from that location. – Joel Fazio May 25 '15 at 17:59
  • The problem is, the SqliteTmp.db file is updated very often and its neccessary to download it seperatly... There is no other option without the assetfolder? – Piet May 25 '15 at 18:18
  • This [tutorial](http://blog.char95.com/importing-sqlite-database-in-android-applications/) explains how to import an existing database. You could use a similar method, just change 'InputStream myInput = context.getAssets().open(DB_NAME);' to your downloaded file stream. – Joel Fazio May 25 '15 at 18:24
  • this is exactly what I did. I almost used the same Code from another example, I will try this tutorial later, thank you – Piet May 25 '15 at 19:22
  • I gonna die here, I got it working for 3 min, then I changed some temporary test paths to the final, and since 2 hours I cant get it work ..... `InputStream myInput = new FileInputStream(new File("storage/sdcard0/Android/data/eu.straff/files/SqliteTmp.db"));` and `private static String DB_PATH = "data/data/eu.straff/databases/";` – Piet May 26 '15 at 18:19
  • Make sure you have your full package name in the path. You can use this to be sure: `DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";` You may want to check out [this](https://github.com/jgilfelt/android-sqlite-asset-helper). – Joel Fazio May 26 '15 at 18:33