简体   繁体   中英

Where Clause is not working in Update but working in Select in Oracle DB

I am trying to execute the below update query

update custom_field cfe set cfe.field_value =:valueId where  cp_entity_id = :cId

0 rows updated.

This is not updating any row but same where clause is working fine with select query and returns 1 row

select * from custom_field where cp_entity_id = :cId

Also, if i hardcode the value of cId parameter then update works fine but I am executing it from java program so it's not possible for me to hardcode the value

Also cp_entity_id column is a foreign key.

Try this, I faced similar issue. Use this select primary_key from custom_field where cp_entity_id = :cId query to find out primary key and Then use that primary key in your where clause of update query.

One of the ways to set parameter is explained here.

PreparedStatement ps = conn.prepareStatement(
  "UPDATE Messages SET description = ?, author = ? WHERE id = ? AND seq_num = ?");

// set the preparedstatement parameters
ps.setString(1,description);
ps.setString(2,author);
ps.setInt(3,id);
ps.setInt(4,seqNum);

// call executeUpdate to execute our sql update statement
ps.executeUpdate();
ps.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM