Databases Reference
In-Depth Information
Improving performance sharing
reusable code
In this recipe, we will see how to share reusable code in our application to improve performance.
Getting ready
To demonstrate the performance gain by sharing reusable code, the following example is
written in Java, similar to the one presented in the previous recipe.
How to do it...
The following steps will demonstrate how to share reusable code:
1.
Create a OraclePerformanceTuningCookbook directory and a chapter02
directory inside it.
2.
Open your preferred text editor.
3.
Create a class called SharedCode in the package chapter02 using the following
code and save it in a file named SharedCode.java in the previously created
chapter02 directory:
package chapter02;
import java.sql.*;
public class SharedCode {
private static final String driver =
"oracle.jdbc.driver.OracleDriver";
private static final String connectionString =
"jdbc:oracle:thin:@localhost:1521:TESTDB";
private static final String user = "hr";
private static final String pass = "hr";
private static final int iterations = 1000;
public static void preparedQuery(Connection conn)
throws SQLException {
try {
PreparedStatement ps = conn.prepareStatement(
"select first_name, last_name
from employees");
for (int j = 0; j < iterations; ++j) {
ResultSet result = ps.executeQuery();
while (result.next()) {
 
Search WWH ::




Custom Search