I am facing a problem. I have no idea is that correct or not.
I am executing a prepared statement query which will return true/false as boolean. When query should executed executed successfully, then it will return true as boolean, but it return as false.
what should I do?
the code is below:
String updateListQuery = "UPDATE RECON_EXCEPTION_ETM_DCR SET GROUP_ID = ?, ASSIGN_DT = SYSDATE WHERE RECON_ID = ? AND UPPER(TRIM(REASON_DESC)) <> 'RECONCILED' AND TRUNC(DUTY_DATE) = ? " ;
try{
conn = Connect.getConn();
getGroupNameStmt = conn.prepareStatement(updateListQuery);
getGroupNameStmt.setString(1, groupId);
getGroupNameStmt.setString(2, reconId);
getGroupNameStmt.setString(3, defFormatDt);
flag = getGroupNameStmt.execute();
flag = true;
}catch(SQLException e){
flag = false;
e.printStackTrace();
}finally{
try{
conn.commit();
getGroupNameStmt.close();
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
For Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE you can use ExecuteUpdate() which returns the number of rows updated, which can be useful when running an update statement. In your case it is not needed, since you know how many records you are inserting.
int updateCount=pst.executeUpdate();
if(updateCount>0)
{
flag=true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With