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.
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 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.
Aucun commentaire:
Enregistrer un commentaire