Spring JDBCTemplate issue

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Spring JDBCTemplate issue



i have a method to update multiple rows in my oracle database using jdbc template.
before updating the application has some processings to do, if these processings are successfully completed it goes on for the update.


HashMap<String, Object> mapUpdate = new HashMap<String, Object>();
mapUpdate.put("ID_REF_STATUT", IConstants.Status.GEN);
mapUpdate.put("DATE_REGLEMENT", new Date());
managerTransactionDao.updateListValeur(listValeurs, mapUpdate);

HashMap<String, Object> mapUpdateBord = new HashMap<String, Object>();
mapUpdateBord.put("ID_STATUS", IConstants.Status.GEN);
mapUpdateBord.put("DATE_GENERATION_DATA", new Date());
mapUpdateBord.put("NOM_FICHIER_DATA", file.getName());
managerTransactionDao.updateBordereau(vbordereau, mapUpdateBord);



below is the update method :


public int updateListValeur(List<VValeur> listValeurs, Map<String, Object> mapAttributForUpdate)

int result = 0;

if (listValeurs != null && !listValeurs.isEmpty())
String listIds = "";
for (VValeur vvaleur : listValeurs)
listIds = listIds + vvaleur.getIdValeur() + " ,";



if (listIds != null && !listIds.equals(""))
listIds = listIds.replace(",)", ")");
try
Object params = new Object[mapAttributForUpdate.size()];
String updateQuery = "UPDATE VALEUR SET ";
if (mapAttributForUpdate != null && !mapAttributForUpdate.isEmpty())
Iterator<Entry<String, Object>> it = mapAttributForUpdate.entrySet().iterator();
int i = 0;
while (it.hasNext())
Map.Entry attValue = (Map.Entry) it.next();
updateQuery = updateQuery + attValue.getKey().toString() + " =? ,";
params[i] = attValue.getValue();
i++;

updateQuery = updateQuery + "where ID_VALEUR in (" + listIds + ")";
updateQuery = updateQuery.replace(",w", "w");
updateQuery = updateQuery.replace(",)", ")");
result = jdbcTemplate.update(updateQuery, params);

catch (Exception e)
ExceptionUtil.log(e);



return result;



the update works fine on 99% of the cases but update failed on some cases even the query is logged to the log file but database values are not updated.





Code in image is a bad practice. Please add the code in question.
– NullPointer
Aug 8 at 10:44





Please edit your question to a Minimal, Complete, and Verifiable example. Also, do not post links to images, but rather include the images in your question.
– Glains
Aug 8 at 10:44





Never catch an exception. I'm assuming you are using Spring to manage your transactions and that might lead to an update getting lost or apparently trying to commit whereas it failed. If you are catching you should rethrow the exception.
– M. Deinum
Aug 8 at 11:22





@Aymen may be your where condition list values returned zero records for update. Have you checked list values against DB when the update failed.
– mallikarjun
Aug 8 at 11:40





@mallikarjun yes i did records exist in the database with the where condition
– Aymen
Aug 8 at 12:13









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS