Home > Software engineering >  Why I cannot put where in SQL?
Why I cannot put where in SQL?

Time:10-18

I'm trying to insert a sublevel to a table from form like in the picture but why can't I use where?

enter image description here

String sql = "insert into BE_Tracker(sub_item) values(?) where id=" id " ";
PreparedStatement st = con.prepareStatement(sql);
st.setString(2,addsubItem);

CodePudding user response:

It sounds like you really wanted an UPDATE here:

String sql = "UPDATE BE_Tracker SET sub_item = ? WHERE id = ?";
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, addsubItem);
st.setString(2, id);
st.executeUpdate();

CodePudding user response:

you cannot use where in insert into query in this way.

You can use it like, something like that insert into MyTable1 select id,name from MyTable2 where id >5

CodePudding user response:

INSERT (...) VALUES (...) query cannot use with finding option WHERE ... = ....

  1. Insert row on table BE_Tracker.
  2. Find rows in table BE_Tracker with 'WHERE' option with 'SELECT', 'UPDATE' or 'DELETE'.
  • Related