这行代码的语法错误?

时间:2021-08-02 01:34:18

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

我是一个尝试在Android应用程序中创建SQLite数据库的初学者,试图使用:

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);

直到运行时才显示错误:SQLiteException:near“CREATE_TABLE”:语法错误:,编译时:CREATE_TABLE Team_info(Home_team_name TEXT,Away_team_name TEXT);

Thanks for the help!

谢谢您的帮助!

2 个解决方案

#1


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

它应该是CREATE TABLE。有空间,而不是下划线。你应该使用StringBuilder而不是连接字符串。例:

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();

#2


Change you create table statement for:

更改您创建表语句:

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

#1


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

它应该是CREATE TABLE。有空间,而不是下划线。你应该使用StringBuilder而不是连接字符串。例:

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();

#2


Change you create table statement for:

更改您创建表语句:

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