Java: Is it ok to set Integer = null? -


I have a function that returns the id number if the argument is present in the database. If not, then it gives blank. Is this an empty indicator begging for an exception? Negative ID numbers are not allowed, but I thought it would be clear for non-existent arguments instead of error-code instead of -1. What do you think?

  The private integer throws SQLException (name of string) tidOfTerm {string sql = "select from term_data WHERE name =?"; Submit Prepared Placement = conn.prepareStatement (sql); Prep.setString (1, name); Results Result = prep.getResultSet (); If (result.next ()) {return result.getInt ("tid"); } Return tap; // TODO: Is it a null pointer to beg for exceptions? }  

This is absolutely legal if you want to avoid any NPE Enter custom exception, but do not return a negative number if the caller does not check the return value, you will always have a problem. But calculating false (because for example, -1 is multiplied) is definitely hard to debug without exception.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -