SQL Best delete record way

Which one is the best way to delete records from DB?

Using Spring JDBC 3.1.1


Query 1:

getJdbcTemplate().execute(SQL, new PreparedStatementCallback<Boolean>() {
            public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
               ps.setString(1, username);
               return ps.execute();

Query 2:

int deletedRecordSize = getJdbcTemplate().update(SQL, username);


As DELETE is an data changing operation you should call executeUpdate in your first Query anyway. This would then return int as well reducing the difference to length and readability of code.

In which case Query 2 looks shorter & cleaner.

Try this try catch block inside ur deleting method:

                String SQL="DELETE FROM XXX WHERE USERNAME=?";
                ps = conn.prepareStatement(sql); //conn here is the usual object fro DB connection class

                ps.setString(1, username);
                JOptionPane.showMessageDialog(null,"DONE DELETING", "DONE",1);
          }catch(SQLException | HeadlessException e){


I think both are the same according to the link


Need Your Help

CPU time discrepancies between static and dynamic allocation

c++ dynamic static fortran allocation

My objective is to investigate the CPU time discrepancies I observe between static and dynamic allocation, depending whether memory is accessed contiguously or not.

What is the best way to implement a DependencyProperty and also avoid 'CA2104: Do not declare read only mutable reference types'?

.net dependency-properties code-analysis fxcop

What is the best way (or, is there a way) to implement a dependency property while avoiding the code analysis warning for CA2104 (Do not declare readonly mutable reference types)?