Databases Reference
In-Depth Information
long stopTimePrep = System.currentTimeMillis();
System.out.println(String.format(
"Execution without prepared query %dms.\n
Execution with prepared query %dms.",
(stopTimeSingle - startTime),
(stopTimePrep - stopTimeSingle)));
} catch (Exception e) {
System.out.println(String.format("Error %s",
e.getLocalizedMessage()));
System.exit(1);
} finally {
conn.close();
}
}
}
4. Open a terminal and make chapter02 the current directory.
5. Build the program using the following command:
javac SharedCode.java
6. Open a terminal and make OraclePerformanceTuningCookbook the current
directory. Run the program from the command line:
java chapter02.SharedCode
7. The output will be as follows:
Matthew Weiss
Jennifer Whalen
Eleni Zlotkey
Execution without prepared query 15198ms.
Execution with prepared query 13033ms.
How it works...
In this example, we have used the singleConnection() method from the previous recipe
and prepared a slightly modified version of the routine, called the preparedQuery() .
The difference between the two methods can be seen in the highlighted section of code, in
preparedQuery() we use a prepared statement to benefit from parsing the query only once.
The timing presented at the end of the processing shows that the preparedQuery()
solution is more than 15 percent faster than the singleConnection() . Increasing the
number of iterations leads to an even greater savings, as it consumes fewer resources than
if the SQL statements are only parsed once.
 
Search WWH ::




Custom Search