Link to home
Start Free TrialLog in
Avatar of Tiago Alexander
Tiago Alexander

asked on

problem with android.database.sqlite.SQLiteException android.database.sqlite.SQLiteException: no such table: Table_name Query

i'm very new to android... but i have a lot experience in programming with PHP(9+ years) and quite a lot but no so much in Java (~3+years)
i just want to create an app that connects to an api (with login and logout), but before that i have to make it offline, i mean using SQLite in order to READ the data (login)
i'm facing a problem that i cannot access to the database sqlite which i already create using sqllite browser using the folloing line
SQLiteDatabase mydatabase = openOrCreateDatabase("test.db", MODE_PRIVATE, null);

Open in new window

i cannot read the user and my app just get out alone
Avatar of Molnár István
Molnár István
Flag of Romania image

you could try this:
try {
   myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);

   /* Create a Table in the Database. */
   myDB.execSQL("CREATE TABLE IF NOT EXISTS "
     + TableName
     + " (Field1 VARCHAR, Field2 INT(3));");

   /* Insert data to a Table*/
   myDB.execSQL("INSERT INTO "
     + TableName
     + " (Field1, Field2)"
     + " VALUES ('Saranga', 22);");

   /*retrieve data from database */
   Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);

   int Column1 = c.getColumnIndex("Field1");
   int Column2 = c.getColumnIndex("Field2");

   // Check if our result was valid.
   c.moveToFirst();
   if (c != null) {
    // Loop through all Results
    do {
     String Name = c.getString(Column1);
     int Age = c.getInt(Column2);
     Data =Data +Name+"/"+Age+"\n";
    }while(c.moveToNext());
   }

Open in new window



hope it helps
For external storage, you need the following permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Avatar of Tiago Alexander
Tiago Alexander

ASKER

i have the following code
 private boolean isUserAndPassBoolean(String username001, String passwd) {




        SQLiteDatabase mydatabase = openOrCreateDatabase("test.db", MODE_ENABLE_WRITE_AHEAD_LOGGING, null);
        Cursor resultSet = mydatabase.rawQuery("SELECT * FROM usuarios WHERE user LIKE '" + username001.toString() + "' AND password LIKE '" + passwd.toString() + "'", null);
        resultSet.moveToFirst();
        String username = resultSet.getString(0);
        String password02 = resultSet.getString(1);
        if ((username001 == username) && (password02 == passwd)) {
            return true;
        } else {
            return false;
            //focusView.requestFocus();
        }
        //return false;

    }

Open in new window

the emulator said me that i have to unistall the previous app
this method which is boolean is where i pass it the username and password as normal strings... (wihout hashing) and after making or telling me that the user should write a username and password
PLEASE HELP
IT TAKES GOOD THE LAYOUT AND THE ACTIVITY... I ALREADY DID IN THE ANDROID MANIFEST THE LINES YOU TOLD ME

IT NOW SAYS
10-17 11:01:43.476 1198-1198/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ejemplo.aplicacion, PID: 1198
    android.database.sqlite.SQLiteException: no such table: usuarios (code 1): , while compiling: SELECT * FROM usuarios WHERE user LIKE 'CORREO' AND password LIKE 'CONTRASE;A'

Open in new window

IN DEED I STARTED WITH THE tutorial you gave me 3 days ago...
here is my android.manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ejemplo001.aplicacioninvertropolis">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".OtraActividad"
            android:label="Pantalla de bienvenida..."
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Open in new window

you could try the following:
1) Settings > Application Manager
2) Select App
3) Clear Data
4) Uninstall App
i already did that... and it's not working
PLEASE DONT LEAVE ME... i really need this job... please please
i had to restart the machine (windows)...
i tried to implement your solution...
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for details.

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.