Reputation:
I'm working on a database project about adding, editing and deleting registries to a Students table which has fields:
Last_names, Names, IcNumber, Average, Entry_mode, Career and Change
In the editing frame i have a field where user types the icnumber of the student to edit its data, asks for the new data and saves it to a "Students" data structure, and then reupdates the registry with the new data:
String stmnt = "Insert Into Students (Last_names, Names, IcNumber, Average, " +
"Entry_mode, Career, Change) Values ('" + student.getLastNames() +
"', '" + student.getNames() + "', '" + student.getIcNumber() + "', " +
student.getAverage() + ", '" + student.getEntry() + "', '" +
student.getCareer() + "', '" + student.getChange() + "') " +
"Where IcNumber = '" + field.getText() + "'";
statement.execute(stmnt);
And i get this Error message:
[Microsoft][Microsoft Access ODBC Driver] "Query input must contain at least one table or query."
I have tried a similar SQL Instruction in the adding registry area of my program without the "Where" condition and works good, anyone knows about that error?
Upvotes: 1
Views: 1054
Reputation: 5446
You should use a subquery, first the SELECT part with WHERE and then the INSERT part Something like:
if (cond){
(SELECT.....)
(INSERT INTO...)}
Upvotes: 2
Reputation: 97111
Use an INSERT statement to add a new record. A WHERE
clause does not belong in an INSERT
statement.
If you're editing an existing record, then you should use an UPDATE statement, and a WHERE
clause makes sense to identify which record to change.
Upvotes: 0
Reputation: 34367
Why are you using where
in a insert
statement? Where
clause is applicable in select
, update
and delete
statements but not in insert
. Also I don't see any need of the where
clause in your query.
Simply use the insert
statement without where
clause.
Upvotes: 0