简体   繁体   English

android.database.sqlite.SQLiteException:“;”附近:语法错误(代码1)

[英]android.database.sqlite.SQLiteException: near “;”: syntax error (code 1)

it say that something is wrong with createTable string, 它说createTable字符串有问题,

My database class.... 我的数据库类。

class DataBase extends SQLiteOpenHelper{
            private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100);";
            private final static String dropTable = "DROP TABLE IF EXISTS"+Keys.Database.TableName+";";

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
                super(context, name, factory, version);
            }

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
                super(context, name, factory, version, errorHandler);
            }


            @Override
            public void onCreate(SQLiteDatabase db) {

                    db.execSQL(createTable);

            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                db.execSQL(dropTable);
                onCreate(db);
            }
        }

and here is some piece of code from where i'm trying to create table 这是我试图创建表的一些代码

public void writeHistory(String date, String type, String city){
        database = new DataBase(context,Keys.Database.DataBaseName,null,Keys.Database.Version);
        SQLiteDatabase sqLiteDatabase = database.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(Keys.Database.Date,date);
        contentValues.put(Keys.Database.Type,type);
        contentValues.put(Keys.Database.City, city);
        long i=sqLiteDatabase.insert(Keys.Database.TableName,null,contentValues);
        if (i<0){
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion FAILED",Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion SUCCESSFUL",Toast.LENGTH_LONG).show();
        }
    }

I'm getting that error while creating the table, please help... thanks in advance.. 创建表格时出现此错误,请帮忙...谢谢。

oops found it... :p 哎呀找到了...:p

private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100));";

it was just a stupid bracket.. 那只是一个愚蠢的支架。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.database.sqlite.SQLiteException:靠近“。”:语法错误(代码1): - android.database.sqlite.SQLiteException: near “.”: syntax error (code 1): , 原因:android.database.sqlite.SQLiteException:附近“”:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): android.database.sqlite.SQLiteException:靠近“UNION”:语法错误 - android.database.sqlite.SQLiteException: near "UNION": syntax error Android Studio 创建数据库错误(android.database.sqlite.SQLiteException: near &quot;and&quot;: syntax error (code 1): )详解 - Android Studio Create Database error (android.database.sqlite.SQLiteException: near "and": syntax error (code 1): ) Detailed Analysis android.database.sqlite.SQLiteException:“WHERE”附近:语法错误(Sqlite 代码 1) - android.database.sqlite.SQLiteException: near “WHERE”: syntax error (Sqlite code 1) 错误:引起:android.database.sqlite.SQLiteException:near“add”:语法错误(代码1): - Error: Caused by: android.database.sqlite.SQLiteException: near “add”: syntax error (code 1): 引起:android.database.sqlite.SQLiteException:near“”:语法错误(代码1):,同时编译: - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): , while compiling: android.database.sqlite.SQLiteException:靠近“ 1”:语法错误(代码1): - android.database.sqlite.SQLiteException: near “1”: syntax error (code 1): , while compiling 造成原因:android.database.sqlite.SQLiteException:“文本”附近:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “text”: syntax error (code 1): 任何人都可以帮助我:android.database.sqlite.SQLiteException:靠近“,”:语法错误(代码1):, - May any one please help me: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): ,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM