android.database.sqlite.SQLiteException:接近“标准":语法错误(代码 1) [英] android.database.sqlite.SQLiteException: near "Standards": syntax error (code 1)

查看:40
本文介绍了android.database.sqlite.SQLiteException:接近“标准":语法错误(代码 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Java 和 Android 开发还很陌生,每当我运行我的活动并尝试在数据库中添加新记录时,我都会收到 SQLiteException 错误.

I'm fairly new to Java and Android development and whenever I run my activity and try to add a new record in the database, I get the SQLiteException error.

在问这里之前我浏览了很多文档并在此页面上搜索了答案,但找不到问题的解决方案,如果有人能帮我找到我在这里遗漏的东西,我将不胜感激.

I went through a lot of documentation before asking here and searched for answers on this page but couldn't find a solution to the problem and I would really appreciate it if anyone could help me find what I'm missing here.

我的日志:

07-21 19:29:13.060 1187-1187/com.lysandros.mars E/SQLiteLog﹕ (1) near"Standards": syntax error 
07-21 19:29:13.099 1187-1187/com.lysandros.mars E/SQLiteDatabase﹕ Error inserting Induction Standards Met=false Business Number= Date of Birth= Workplace= Notes= Name= Email= Telephone Number= Sick Pay=Sickness Pay Job Title=Deputy Manager Address= Surname= Department= Start Date=
      android.database.sqlite.SQLiteException: near "Standards": syntax error (code 1): , while compiling: INSERT INTO EmployeeTable(Induction Standards Met,Business Number,Date of Birth,Workplace,Notes,Name,Email,Telephone Number,Sick Pay,Job Title,Address,Surname,Department,Start Date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
        at com.lysandros.mars.EmployeeDatabaseAdapter.insertData(EmployeeDatabaseAdapter.java:53)
        at com.lysandros.mars.Form$1.onClick(Form.java:78)
        at android.view.View.performClick(View.java:4204)
        at android.view.View$PerformClick.run(View.java:17355)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

包含错误之一的数据库活动部分:

The part of the database activity that contains one of the errors:

public class EmployeeDatabaseAdapter {
DatabaseHelper helper;
public EmployeeDatabaseAdapter(Context context) {
    helper = new DatabaseHelper(context);
}

public long insertData (String name,
                        String surname,
                        String tnumber,
                        String bnumber,
                        String email,
                        String address,
                        String dob,
                        String department,
                        String jobtitle,
                        String workplace,
                        String stardate,
                        Boolean ISM,
                        Boolean ISM2,
                        String spay,
                        String notes)
{
    SQLiteDatabase db = helper.getWritableDatabase();

    ContentValues contentValues =  new ContentValues();
    contentValues.put(DatabaseHelper.COLUMN_NAME, name);
    contentValues.put(DatabaseHelper.COLUMN_SURNAME, surname);
    contentValues.put(DatabaseHelper.COLUMN_NUMBER, tnumber);
    contentValues.put(DatabaseHelper.COLUMN_BNUMBER, bnumber);
    contentValues.put(DatabaseHelper.COLUMN_EMAIL, email);
    contentValues.put(DatabaseHelper.COLUMN_ADDRESS, address);
    contentValues.put(DatabaseHelper.COLUMN_DOB, dob);
    contentValues.put(DatabaseHelper.COLUMN_DEPARTMENT, department);
    contentValues.put(DatabaseHelper.COLUMN_JOBTITLE, jobtitle);
    contentValues.put(DatabaseHelper.COLUMN_WORKPLACE, workplace);
    contentValues.put(DatabaseHelper.COLUMN_STARTDATE, stardate);
    contentValues.put(DatabaseHelper.COLUMN_STANDARDS, ISM);
    contentValues.put(DatabaseHelper.COLUMN_STANDARDS2, ISM2);
    contentValues.put(DatabaseHelper.COLUMN_SPAY, spay);
    contentValues.put(DatabaseHelper.COLUMN_NOTES, notes);

    long id = db.insert(DatabaseHelper.TABLE_NAME, null, contentValues);
    return id;


}

static class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "EmployeeDatabase";

    private static final String TABLE_NAME = "EmployeeTable";

    private static final int DATABASE_VERSION = 1;

    private static final String COLUMN_UID = "_id";
    private static final String COLUMN_NAME = "Name";
    private static final String COLUMN_SURNAME = "Surname";
    private static final String COLUMN_NUMBER = "Telephone Number";
    private static final String COLUMN_BNUMBER = "Business Number";
    private static final String COLUMN_EMAIL = "Email";
    private static final String COLUMN_ADDRESS = "Address";
    private static final String COLUMN_DOB = "Date of Birth";
    private static final String COLUMN_DEPARTMENT = "Department";
    private static final String COLUMN_JOBTITLE = "Job Title";
    private static final String COLUMN_WORKPLACE = "Workplace";
    private static final String COLUMN_STARTDATE = "Start Date";
    private static final String COLUMN_STANDARDS = "Induction Standards Met";
    private static final String COLUMN_STANDARDS2 = "Induction Standards Met";
    private static final String COLUMN_SPAY = "Sick Pay";
    private static final String COLUMN_NOTES = "Notes";
    private static final String COLUMN_HOLIDAYENT = "Holiday Entitlement";
    private static final String COLUMN_HOLIDAYTKN = "Holiday Taken";
    private static final String COLUMN_HOLIDAYBKD = "Holiday Booked";
    private static final String COLUMN_HOLIDAYRMN = "Holiday Remaining";
    private static final String COLUMN_TSICKENESS = "Total Sickness";
    private static final String COLUMN_TLATENESS = "Total Lateness";
    private static final String COLUMN_OTHERABSENCES = "Other Absences";
    private static final String COLUMN_SUPERVISIONS = "Supervisions";
    private static final String COLUMN_PRBREVIEWS = "Probation Reviews";
    private static final String COLUMN_PRFMREVIEWS = "Performance Reviews";

    private static final String CREATE_TABLE = "CREATE TABLE "+TABLE_NAME+" ("+COLUMN_UID+" INTEGER PRIMARY KEY AUTOINCREMENT," +
            " "+COLUMN_NAME+" VARCHAR(255)," +
            " "+COLUMN_SURNAME+" VARCHAR(255)," +
            " "+COLUMN_NUMBER+" INTEGER," +
            " "+COLUMN_BNUMBER+" INTEGER," +
            " "+COLUMN_EMAIL+" INTEGER," +
            " "+COLUMN_ADDRESS+" VARCHAR(255)," +
            " "+COLUMN_DOB+" DATE," +
            " "+COLUMN_DEPARTMENT+" VARCHAR(255)," +
            " "+COLUMN_JOBTITLE+" VARCHAR(255)," +
            " "+COLUMN_WORKPLACE+" VARCHAR(255)," +
            " "+COLUMN_STARTDATE+" DATE," +
            " "+COLUMN_STANDARDS+" BOOLEAN," +
            " "+COLUMN_STANDARDS2+" BOOLEAN, " +
            " "+COLUMN_SPAY+" BOOLEAN, " +
            " "+COLUMN_NOTES+" TEXT, " +
            " "+COLUMN_HOLIDAYENT+" SMALLINT," +
            " "+COLUMN_HOLIDAYTKN+" SMALLINT," +
            " "+COLUMN_HOLIDAYBKD+" SMALLINT," +
            " "+COLUMN_HOLIDAYRMN+" SMALLINT," +
            " "+COLUMN_TSICKENESS+" SMALLINT," +
            " "+COLUMN_TLATENESS+" SMALLINT," +
            " "+COLUMN_OTHERABSENCES+" SMALLINT," +
            " "+COLUMN_SUPERVISIONS+" SMALLINT," +
            " "+COLUMN_PRBREVIEWS+" SMALLINT," +
            " "+COLUMN_PRFMREVIEWS+" SMALLINT);";

我用来在数据库中添加数据的表单活动部分:

The part of the form activity that I'm using to add data in the database:

    final EditText nameField = (EditText) findViewById(R.id.name);
    final EditText surnameField = (EditText) findViewById(R.id.surname);
    final EditText tnumberField = (EditText) findViewById(R.id.tnumber);
    final EditText bnumberFeild = (EditText) findViewById(R.id.bnumber);
    final EditText emailField = (EditText) findViewById(R.id.email);
    final EditText addressField = (EditText) findViewById(R.id.address);
    final EditText dobField = (EditText) findViewById(R.id.dob);
    final EditText departmentField = (EditText) findViewById(R.id.department);
    final Spinner jobtitleSpinner = (Spinner) findViewById(R.id.jobtitletype);
    final EditText workplaceField = (EditText) findViewById(R.id.workplace);
    final EditText sdateField = (EditText) findViewById(R.id.sdate);
    final CheckBox ismCheckBoxFieldYes = (CheckBox) findViewById(R.id.ISM1);
    final CheckBox ismCheckBoxFieldNo = (CheckBox) findViewById(R.id.ISM2);
    final Spinner SPAYSpinner = (Spinner) findViewById(R.id.sicknesspaytype);
    final EditText notesField = (EditText) findViewById(R.id.notes);

    Button addrecord = (Button) findViewById(R.id.AddEmployee);

    dbhelper = new EmployeeDatabaseAdapter(this);

    addrecord.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String name = nameField.getText().toString();
            String surname = surnameField.getText().toString();
            String tnumber = tnumberField.getText().toString();
            String bnumber = bnumberFeild.getText().toString();
            String email = emailField.getText().toString();
            String address = addressField.getText().toString();
            String dob = dobField.getText().toString();
            String department = departmentField.getText().toString();
            String jobtitletype = jobtitleSpinner.getSelectedItem().toString();
            String workplace = workplaceField.getText().toString();
            String sdate = sdateField.getText().toString();
            boolean bRequiresResponse = ismCheckBoxFieldYes.isChecked();
            boolean bReuiresResponse2 = ismCheckBoxFieldNo.isChecked();
            String SPAY = SPAYSpinner.getSelectedItem().toString();
            String notes = notesField.getText().toString();

            dbhelper.insertData(name, surname, tnumber, bnumber, email, address, dob, department, jobtitletype, workplace, sdate, bRequiresResponse, bReuiresResponse2, SPAY, notes);

        }
    });

我是否需要添加其他内容,请告诉我..我尝试包含尽可能少的内容,但同时包含您识别问题所需的所有必要信息.

Should I require to add something else please let me know..I tried to include as less as possible but at the same time, all the necessary information that you would need to identify the problem.

推荐答案

列名不能有空格.您需要更改它们,例如Induction_Standards_MetInductionStandardsMet

Column names cannot have spaces. You need to change them, e.g. Induction_Standards_Met or InductionStandardsMet

这篇关于android.database.sqlite.SQLiteException:接近“标准":语法错误(代码 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆