android.database.sqlite.SQLiteException: near "Standards": syntax error (code 1) -
i'm new java , android development , whenever run activity , try add new record in database, sqliteexception error.
i went through lot of documentation before asking here , searched answers on page couldn't find solution problem , appreciate if me find i'm missing here.
my logcat:
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 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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?) @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:882) @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:493) @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31) @ android.database.sqlite.sqlitedatabase.insertwithonconflict(sqlitedatabase.java:1467) @ android.database.sqlite.sqlitedatabase.insert(sqlitedatabase.java:1339) @ com.lysandros.mars.employeedatabaseadapter.insertdata(employeedatabaseadapter.java:53) @ com.lysandros.mars.form$1.onclick(form.java:78) @ android.view.view.performclick(view.java:4204) @ android.view.view$performclick.run(view.java:17355) @ android.os.handler.handlecallback(handler.java:725) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5041) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method)
the part of database activity contains 1 of 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 form activity i'm using add data in 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 require add else please let me know..i tried include less possible @ same time, necessary information need identify problem.
column names cannot have spaces. need change them, e.g. induction_standards_met
or inductionstandardsmet
Comments
Post a Comment