0

I'm brand new to developing and I am getting the following error in android:

08-24 23:55:15.744: E/AndroidRuntime(29803): Caused by: android.database.sqlite.SQLiteException: no such column: customerName (code 1): , while compiling: INSERT INTO nncdjiftable (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03) VALUES (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03)

This is my code:

nncdjifdb.execSQL("CREATE TABLE IF NOT EXISTS nncdjiftable(customerName VARCHAR,timeShift VARCHAR,date01 VARCHAR,vendorGameThemePT VARCHAR,managerSignature VARCHAR,managerDate VARCHAR,jackpotAmount VARCHAR,lessTaxesWithheld VARCHAR,cashier VARCHAR,taxRate VARCHAR,slotAttendant VARCHAR,totalAmountPaid VARCHAR,slotSupervisorMOD VARCHAR,customerSignature VARCHAR,date03 VARCHAR);");

nncdjifdb.execSQL("INSERT INTO nncdjiftable (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03) VALUES (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03)");

I've been using a tutorial to make this and have gotten stuck at a few points where it was using certain syntax so I had to modify it but it seems like I broke it more, I looked around on here quite a bit using SQLITE no such column but it looks like a lot of them are using difference syntax, that I don't quite understand since I'm still brand new to this.

Any help is appreciated.

4 Answers4

0

If you've run the example before chanches are that the table is already made before you made changes to the CREATE TABLE statement.

Because the table already exists it won't execute the CREATE TABLE with the new columns and because those columns don't exist, you're getting that error on the INSERT INTO statement.

You have a couple of options:

  • Clear the app data so that the database is deleted
  • Execute a DROP TABLE nncdjiftable to delete the table
  • Execute ALTER TABLE ADD COLUMN statement to add the missing columns.

The first 2 are the easiest, but you will lose the data that's in the database/table.

Drakarah
  • 2,094
  • 2
  • 22
  • 22
0

You need to provide your variables to the INSERT statement. Please see the pattern you should use here below:

nncdjifdb.execSQL("INSERT INTO nncdjiftable 
(customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03) 
VALUES ('"+someVariable+"',"+...+")");

Semicolons in the strings are optional using execSQL.

Also, I saw the Java code before it was taken down; so I can confirm that you do have valid values in your variables.

d'alar'cop
  • 2,342
  • 1
  • 12
  • 17
  • Just to clear it up I would need to go VALUES("+customerName", "+timeShift") and so on? – user2714974 Aug 25 '13 at 08:02
  • yes, it is a pattern; the ellipsis "..." continues on. So, yes you would need to do the aVariable+","+aVariable2 pattern until all your variables are represented against the columns – d'alar'cop Aug 25 '13 at 08:03
  • @user2714974 actually - see the new pattern - it is more correct. the commas will need to be within the double quotes - and strings will need to be enclosed with single quotes inside the double quotes. (see above) – d'alar'cop Aug 25 '13 at 08:05
  • Please use a prepared statement for that query otherwise you're wide open to a SQL injection. (It's good to have a habit of doing so all the time). – Drakarah Aug 25 '13 at 08:08
  • Yes good point. OP: If SQL injection is a risk please refer to this - http://stackoverflow.com/questions/433392/how-do-i-use-prepared-statements-in-sqlite-in-android – d'alar'cop Aug 25 '13 at 08:10
  • Am now getting the following: 08-25 01:16:14.116: E/AndroidRuntime(2834): Caused by: android.database.sqlite.SQLiteException: table nncdjiftable has no column named cashierSignature (code 1): , while compiling: INSERT INTO nncdjiftable (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03) VALUES ('like', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); Erm, found that issue. – user2714974 Aug 25 '13 at 08:17
  • @user2714974 Can you comment the line of java code that is doing the insert please. – d'alar'cop Aug 25 '13 at 08:19
  • nncdjifdb.execSQL("INSERT INTO nncdjiftable (customerName, timeShift, date01, vendorGameThemePT, managerSignature, managerDate, jackpotAmount, lessTaxesWithheld, cashierSignature, taxRate, slotAttendantSignature, totalAmountPaid, slotSupervisorMODSignature, customerSignature, date03) VALUES ('"+customerName+"', '"+timeShift+"', '"+date01+"', '"+vendorGameThemePT+"', '"+managerSignature+"', '"+managerDate+"', '"+jackpotAmount+"', '"+lessTaxesWithheld+"', '"+cashierSignature+"', '"+taxRate+"', '"+slotAttendantSignature+"', '"+totalAmountPaid+"', '"+slotSupervisorMODSignature+"');"); – user2714974 Aug 25 '13 at 08:23
  • @user2714974 it could be the CREATE TABLE line - are you sure about the column name there?... could also the variable within the java code - it is the same? - MAY also be the fact that some data types will not need the single quotes - and may actually cause it not to work. – d'alar'cop Aug 25 '13 at 08:29
  • Heh, I found the issue, I had the column created as a different name than where the data was being sent to. Everything is good now. – user2714974 Aug 25 '13 at 08:48
0

I'm not sure about SQL but if you notice in first .execSQL it ends with

,date03 VARCHAR);");

and in the second

, date03)");

notice the ; after ) in the quotation.

Ahmed Ekri
  • 4,342
  • 3
  • 19
  • 42
0

I'm not sure if you haven't posted some relevant code, but it looks like you haven't given your variables a value...e.g. customerName = "customerName"... etc.

kwishnu
  • 1,549
  • 15
  • 16