Ankur Singh
Ankur Singh

Reputation: 335

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.

Upvotes: 0

Views: 889

Answers (2)

jeetendra Mandal
jeetendra Mandal

Reputation: 150

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();

Upvotes: 0

Vidhu Shekhar
Vidhu Shekhar

Reputation: 51

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.

Upvotes: 1

Related Questions