Skip to content
Advertisement

near “”: syntax error in SQL with android studio

I’m working on a SQL databse on java (android studio project) but i have a weird mistake. Basically, everytime i have

near "Hello": syntax error in "INSERT INTO GAMES(_id, PRICE, NAME, DEV, PLATFORM) VALUES (0, 70, Hello, Henri, Terrain)"

I have tried like this

public void addGame(String Price, String Name, String Dev, String Platform) {
    database = getWritableDatabase();
    database.execSQL("INSERT INTO "+ SchemeDB.TAB_GAMES +"("
            + DBS.COL_GAMES_ID +", "
            + DBS.COL_GAMES_PRICE +", "
            + DBS.COL_GAMES_NAME +", "
            + DBS.COL_GAMES_DEV +", "
            + DBS.COL_GAMES_PLATFORM +") VALUES (" + i +", "
            + Price +", "
            + Name +", "
            + Dev +", "
            + Platform +")");
    database.close();

}

My DBS is

public interface SchemeDB {

    int VERSION = 1;
    String DB_NAME = "????";
    String TAB_GAMES = "???";
    String COL_GAMES_ID = "_id";
    String COL_GAMES_PRICE = "PRICE";
    String COL_GAMES_NAME = "NAME";
    String COL_GAMES_DEV = "DEV";
    String COL_GAMES_PLATFORM = "PLATFORM";

}

And i really don’t see where is the mistake. Because they’re saying “syntax error”, but for me, it’s look pretty OKAY. Anyone have a clue ? I’m just trying to insert some things in my Database.

Advertisement

Answer

Something like this…

    + "'" + Name + "', "
    + "'" + Dev  + "', "
    + "'" + Platform + "')");
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement