Image

Imagegrrlpower wrote in Imagejava_dev 😡frustrated

Listens: tracy chapman

jdbc (again)

ok, so explain me this.

PreparedStatement ps = con.prepareStatement("INSERT INTO ITEMS VALUES( ?, ?, ?, ?);");
  ps.setString(1, up);
  ps.setString(2, de);
  ps.setString(3, ud);
  ps.setInt(4, qnt);
  ps.executeUpdate();

works...

int changed = -1;
PreparedStatement ps = con.prepareStatement("DELETE FROM ITEMS WHERE UPC = ?");
ps.setString(1, up);
changed = ps.executeUpdate();

if (changed <= 0)
   throw new NoSuchItemException();

works...

st = con.createStatement();
rs = st.executeQuery("select * from ITEMS;");

works....

st = con.createStatement();
rs = st.executeQuery("select * from ITEMS WHERE QUANTITY < 10;");

DOESN'T work

PreparedStatement ps = con.prepareStatement("SELECT * FROM ITEMS WHERE QUANTITY = ?");
  ps.setString(1, 10);
  rs = ps.executeQuery();

DOESN'T work.

(the last two do not seem to recognize the WHERE clause - the first one returns all records, and the second seems to arbirtraily show some of them...)