Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link
  1. +1 to Alex and an improvement for Java 6: you could eliminate the null check in the finally block if you move the DerbyDog.getResultSet call before the try block. If it's inside the try block and it throws an exception you won't be able to close the ResultSet because the reference will remain null. Guideline 1-2: Release resources in all cases in the Secure Coding Guidelines for the Java Programming Language, Version 4.0 documentation could be helpful.

  2. The catch block is unnecessary here. Exceptions will be propagated without it.

  3. Be aware of static helper classes. DerbyDog seems one of them. You might find my former answer about itmy former answer about it useful.

ResultSet resultSet = DerbyDog.getResultSet(strSelect);
try {
    if (resultSet.next()) {
        resultSet.updateString(COLUMN_STATUS, strStatus);
        resultSet.updateRow();
    }
} finally {
        resultSet.close();
}
  1. +1 to Alex and an improvement for Java 6: you could eliminate the null check in the finally block if you move the DerbyDog.getResultSet call before the try block. If it's inside the try block and it throws an exception you won't be able to close the ResultSet because the reference will remain null. Guideline 1-2: Release resources in all cases in the Secure Coding Guidelines for the Java Programming Language, Version 4.0 documentation could be helpful.

  2. The catch block is unnecessary here. Exceptions will be propagated without it.

  3. Be aware of static helper classes. DerbyDog seems one of them. You might find my former answer about it useful.

ResultSet resultSet = DerbyDog.getResultSet(strSelect);
try {
    if (resultSet.next()) {
        resultSet.updateString(COLUMN_STATUS, strStatus);
        resultSet.updateRow();
    }
} finally {
        resultSet.close();
}
  1. +1 to Alex and an improvement for Java 6: you could eliminate the null check in the finally block if you move the DerbyDog.getResultSet call before the try block. If it's inside the try block and it throws an exception you won't be able to close the ResultSet because the reference will remain null. Guideline 1-2: Release resources in all cases in the Secure Coding Guidelines for the Java Programming Language, Version 4.0 documentation could be helpful.

  2. The catch block is unnecessary here. Exceptions will be propagated without it.

  3. Be aware of static helper classes. DerbyDog seems one of them. You might find my former answer about it useful.

ResultSet resultSet = DerbyDog.getResultSet(strSelect);
try {
    if (resultSet.next()) {
        resultSet.updateString(COLUMN_STATUS, strStatus);
        resultSet.updateRow();
    }
} finally {
        resultSet.close();
}
Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

  1. +1 to Alex and an improvement for Java 6: you could eliminate the null check in the finally block if you move the DerbyDog.getResultSet call before the try block. If it's inside the try block and it throws an exception you won't be able to close the ResultSet because the reference will remain null. Guideline 1-2: Release resources in all cases in the Secure Coding Guidelines for the Java Programming Language, Version 4.0 documentation could be helpful.

  2. The catch block is unnecessary here. Exceptions will be propagated without it.

  3. Be aware of static helper classes. DerbyDog seems one of them. You might find my former answer about it useful.

ResultSet resultSet = DerbyDog.getResultSet(strSelect);
try {
    if (resultSet.next()) {
        resultSet.updateString(COLUMN_STATUS, strStatus);
        resultSet.updateRow();
    }
} finally {
        resultSet.close();
}