Java EE 7 Recipes: A Problem-Solution Approach by Josh Juneau

Java EE 7 Recipes: A Problem-Solution Approach by Josh Juneau

Author:Josh Juneau [Juneau, Josh]
Language: eng
Format: epub, pdf
Tags: Apress, Computers, Programming Languages, Web, Web Programming, Java
ISBN: 9781430244257
Publisher: Apress
Published: 2013-05-22T04:00:00+00:00


}

if (conn != null) {

try {

conn.close();

conn = null;

} catch (SQLException ex) {

ex.printStackTrace();

}

}

return author;

}

You can see that the PreparedStatement object that was instantiated, stmt, is checked to see whether it is NULL. If not, it is closed by calling the close method. Working through the code in the solution to this recipe, you can see that similar code is used to process database insert, update, and delete statements. The only difference in those cases is that the PreparedStatement executeUpdate method is called rather than the executeQuery method. The executeUpdate method will return an int value representing the number of rows affected by the SQL statement.

The use of PreparedStatement objects is preferred over JDBC Statement objects. This is because they are more secure and perform better. They can also make your code easier to follow and easier to maintain.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.