View RSS Feed

JDBC

Java Database Connectivity (JDBC) examples. SQL with Java.

  1. PreparedStatement Performance

    by , 04-27-2012 at 07:11 PM
    It takes time for a database to parse an SQL string, and create a query plan for it. A query plan is an analysis of how the database can execute the query in the most efficient way.
    If you submit a new, full SQL statement for every query or update to the database, the database has to parse the SQL and for queries create a query plan. By reusing an existing PreparedStatement you can reuse both the SQL parsing and query plan for subsequent queries. This speeds up query execution, by decreasing ...
  2. Supplying Values for PreparedStatement Parameters

    by , 04-27-2012 at 07:08 PM
    You must supply values in place of the question mark placeholders (if there are any) before you can execute a PreparedStatement object. Do this by calling one of the setter methods defined in the PreparedStatement class. The following statements supply the two question mark placeholders in the PreparedStatement named updateSales:

    Java Code:
    updateSales.setInt(1, e.getValue().intValue());
    updateSales.setString(2, e.getKey());
    The first argument for each of ...