Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android.database.sqlite.SQLiteException:near"&引用;:语法错误(代码1):,_Java_Android_Sqlite - Fatal编程技术网

Java android.database.sqlite.SQLiteException:near"&引用;:语法错误(代码1):,

Java android.database.sqlite.SQLiteException:near"&引用;:语法错误(代码1):,,java,android,sqlite,Java,Android,Sqlite,我相当肯定我的更新代码也不正确,如果有人能告诉我如何在一个表中实现电话号码和出生数据,那就太好了。真的很难让一切顺利 public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "contacts.db"; private static fi

我相当肯定我的更新代码也不正确,如果有人能告诉我如何在一个表中实现电话号码和出生数据,那就太好了。真的很难让一切顺利

public class DatabaseHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "contacts.db";
    private static final String TABLE_NAME = "contacts";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_FORENAME = "name";
    private static final String COLUMN_SURNAME = "Surname";
    private static final String COLUMN_UNAME = "uname";
    private static final String COLUMN_PASS = "pass";
    private static final String COLUMN_DOB = "D.O.B";
    private static final String COLUMN_CONTACTNO = "contact_number";

    SQLiteDatabase db;
    private static final String TABLE_CREATE ="create table contacts (id integer primary key , forename text ," +
            " surname text , uname text , pass text , D.O.B integer ,contact_number integer )";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
        this.db = db;

    }

    public void  insertContact(Contact c) {
        db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        String query = "Select * from contacts";
        Cursor cursor = db.rawQuery(query, null);
        int count = cursor.getCount();

        values.put(COLUMN_ID, count);
        values.put(COLUMN_FORENAME, c.getForename());
        values.put(COLUMN_SURNAME, c.getSurname());
        values.put(COLUMN_UNAME, c.getUname());
        values.put(COLUMN_PASS, c.getPass());
        values.put(COLUMN_DOB, c.getDOB());
        values.put(COLUMN_CONTACTNO, c.getContactNo());

        db.insert(TABLE_NAME, null, values);
        db.close();
    }

    public String searchPass(String uname) {
        db = this.getReadableDatabase();
        String query = "Select uname,pass from "+TABLE_NAME;
        Cursor cursor = db.rawQuery(query, null);
        String a, b;
        b = "not found";
        if(cursor.moveToFirst()){
            do{
                a = cursor.getString(0);

                if(a.equals(uname)){
                    b = cursor.getString(1);
                    break;
                }
            }
                    while(cursor.moveToNext());
        }

        return b;
    }

    public boolean updateData(String uname, String pass, String contactNo ){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COLUMN_UNAME, uname);
        contentValues.put(COLUMN_PASS, pass);
        contentValues.put(COLUMN_CONTACTNO, contactNo);
        db.update(TABLE_NAME, contentValues, "uname = ?", new String[] { uname });
        return true;
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String query = "Drop table IF EXISTS "+TABLE_NAME;
        db.execSQL(query);
        this.onCreate(db);
    }
}

尝试下面的查询,并将您的日期保存在字符串中,您只需键入cast即可

private static final String TABLE_CREATE ="CREATE TABLE contacts ( id INTEGER PRIMARY KEY AUTOINCREMENT, forename TEXT," +
        " surname TEXT, uname TEXT, pass TEXT, DOB TEXT, contact_number INTEGER )";

尝试删除出生日期字段中的点,即将
D.O.B
更改为simple
dob
修改DB列或任何与DB相关的更改后,您需要更改DB版本或完全卸载应用程序。您好,谢谢回复!我现在遇到了这个android.database.sqlite.sqlite异常:table contacts没有名为姓氏的列(代码1):,我不知道它告诉我没有名为姓氏的列,但我找不到它应该在哪里,因为我认为它在正确的位置。您正在将列\u姓氏字符串初始化为列\u姓氏=“姓氏”;而不是列_姓氏=“姓氏”;Yeah your right@matthew只是将S更改为S,因为在创建表时,您使用的是姓氏,并且您正在尝试使用姓氏获取值,所以请更正它并再次运行:)我更改了它,并按照建议添加了注释,但姓氏错误仍然存在。插入姓氏=qweqw contactNo=null forename=qwe dob=null pass=111 id=3 uname=qwee android.database.sqlite.SQLiteException:table contacts没有名为姓氏的列您只需卸载应用程序并清理生成并重新安装,如果错误仍然存在,请重试一次有人告诉我