-1

I am creating database for an application ,Here is my code giving me error no such table found where is the problem please help

protected static final String player = ("CREATE TABLE " + table_player
            + " (" + player_id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + player_name + " TEXT, " + player_dob + "INTEGER" + player_gender + " TEXT);");

in oncreatdatabase()

db.execSQL(player);

insert method:

public long insert_Place(  )//, String _Placealti)
    {    
        try
        {
            SQLiteDatabase db= this.getWritableDatabase();
            ContentValues contentValues = new ContentValues();  
            contentValues.put(player_name, "name"); 
            contentValues.put(player_dob,  "123");
            contentValues.put(player_gender, "male");

            return db.insert(table_player, null, contentValues);
        }
        catch(Exception ex)
        {
            Log.d("Insert:  insert_Place",ex.toString());
        }
        return 0;
    }
Bibi Tahira
  • 1,082
  • 5
  • 15
  • 39
  • 4
    There are SQL syntax problems but the error you're seeing suggests the SQL has not even been run in the first place. Uninstall your app first and fix the missing whitespace and commas in the `CREATE TABLE` (to get rid of the "no such column" errors). – laalto Sep 24 '14 at 11:27
  • 1
    Put `,` after second `INTEGER` – SerCna Sep 24 '14 at 11:28
  • 1
    its always best to test out your sql statements before embeddeding them in your application. or atleast Log.v(TAG,"sql = " + player); from within your app to ensure the sql is valid – Hector Sep 24 '14 at 11:30
  • just write "INTEGER" like this " INTEGER," – Shah Sep 24 '14 at 12:57

3 Answers3

2

Missed , after INTEGER and also add one space between Column Name and Column Type

+ " INTEGER " + player_gender + " + " TEXT);")//  Missed , after INTEGER and add one space before INTEGER

Correct:

protected static final String player = ("CREATE TABLE " + table_player
        + " (" + player_id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
        + player_name + " TEXT, " + player_dob + " INTEGER," + player_gender + " TEXT);");

That's why your table is not crated and you got NO Such table found Exception

M D
  • 47,665
  • 9
  • 93
  • 114
1

The table isn't being created due to a syntax error:

player_name + " TEXT, " + player_dob + "INTEGER" + player_gender + " TEXT);"

should be

player_name + " TEXT, " + player_dob + " INTEGER, " + player_gender + " TEXT);"
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
1
//write to this

String player = "CREATE TABLE IF NOT EXISTS "
            + table_player + "(" + player_id
                      + " integer primary key , " + player_name
                      + " text ,"+ player_dob+" integer,"+player_gender+" text);";