0

I'm a beginner trying to create a SQLite Database in an android application, trying to use:

public String CREATE_QUERY = "CREATE_TABLE " +TableInfo.TABLE_NAME+
            " (" +TableInfo.HOME_TEAM+ " TEXT, " +TableInfo.AWAY_TEAM+ " TEXT);" ;

No errors displaying until runtime which gives: SQLiteException: near "CREATE_TABLE": syntax error: , while compiling: CREATE_TABLE Team_info (Home_team_name TEXT, Away_team_name TEXT);

Thanks for the help!

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 5
    Perhaps you meant `CREATE TABLE` instead of `CREATE_TABLE`? That would certainly be more conventional SQL... – Jon Skeet May 08 '15 at 16:03

2 Answers2

2

It should be CREATE TABLE. with a space, not a underscore. And you should use a StringBuilder instead of concatenating strings. Example:

StringBuilder sb = new StringBuilder();
    sb.append("CREATE TABLE ");
    sb.append(TableInfo.TABLE_NAME);
    sb.append(" (");
    sb.append(TableInfo.HOME_TEAM);
    sb.append(" TEXT, ");
    sb.append(TableInfo.AWAY_TEAM);
    sb.append(" TEXT);");

    public String CREATE_QUERY = sb.toString();
Sandeep Kaul
  • 2,957
  • 2
  • 20
  • 36
  • 1
    Modern Java compiler automatically compile string concat operations into StringBuilder operations: See http://stackoverflow.com/questions/1532461/stringbuilder-vs-string-concatenation-in-tostring-in-java – Robert May 08 '15 at 16:19
0

Change you create table statement for:

public String CREATE_QUERY = "CREATE TABLE " +TableInfo.TABLE_NAME+
        " (" +TableInfo.HOME_TEAM+ " TEXT, " +TableInfo.AWAY_TEAM+ " TEXT);" ;
antonio
  • 18,044
  • 4
  • 45
  • 61