Reusing a Statement Object..

.. and the ResultSet!

Quoting from this book:
The PreparedStatement object instance is constructed before the final query is executed, allowing you to modify the parameters of the query without having to construct a new Statement object every time.
which makes me think.. "Do I need to create a new Statement object every time I need to execute a query?".

Here is the example I have, which works just fine..
import java.sql.*;
 
public class ReusingStatementExample {
 
    private final static String url = "jdbc:h2:~/sampleh2db;TRACE_LEVEL_FILE=0;AUTO_SERVER=TRUE";
    private final static String user = "test";
    private final static String password = "test";
 
    public static void main(String[] args) throws SQLException {
        final Connection connection = DriverManager.getConnection(url, user, password);
        final Statement statement = connection.createStatement();
 
        System.out.println("SELECT * FROM EMPLOYEE WHERE CITY = 'Rotkreuz'");
        ResultSet resultSet = statement.executeQuery("SELECT * FROM EMPLOYEE WHERE CITY = 'Rotkreuz'");
        reportResultSet(resultSet);
 
        System.out.print(System.getProperty("line.separator"));
 
        System.out.println("SELECT * FROM EMPLOYEE WHERE CITY = 'Luzern'");
        resultSet = statement.executeQuery("SELECT * FROM EMPLOYEE WHERE CITY = 'Luzern'");
        reportResultSet(resultSet);
 
        statement.close();
        resultSet.close();
        connection.close();
    }
 
    private static void reportResultSet(ResultSet resultSet) throws SQLException {
        while (resultSet.next()) {
            System.out.print(resultSet.getString("FIRSTNAME") + "\t");
            System.out.print(resultSet.getString("LASTNAME") + "\t");
            System.out.println(resultSet.getString("CITY"));
        }
    }
}

Here is an example with a PreparedStatement..
import java.sql.*;
 
public class PreparedStatementExample {
 
    private final static String url = "jdbc:h2:~/sampleh2db;TRACE_LEVEL_FILE=0;AUTO_SERVER=TRUE";
    private final static String user = "test";
    private final static String password = "test";
 
    public static void main(String[] args) throws SQLException {
        final Connection connection = DriverManager.getConnection(url, user, password);
        final PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM EMPLOYEE WHERE CITY = ?");
        preparedStatement.setString(1, "Rotkreuz");
 
        System.out.println("SELECT * FROM EMPLOYEE WHERE CITY = 'Rotkreuz'");
        ResultSet resultSet = preparedStatement.executeQuery();
        reportResultSet(resultSet);
 
        System.out.print(System.getProperty("line.separator"));
 
        System.out.println("SELECT * FROM EMPLOYEE WHERE CITY = 'Luzern'");
        preparedStatement.setString(1, "Luzern");
        resultSet = preparedStatement.executeQuery();
        reportResultSet(resultSet);
 
        preparedStatement.close();
        resultSet.close();
        connection.close();
    }
 
    private static void reportResultSet(ResultSet resultSet) throws SQLException {
        while (resultSet.next()) {
            System.out.print(resultSet.getString("FIRSTNAME") + "\t");
            System.out.print(resultSet.getString("LASTNAME") + "\t");
            System.out.println(resultSet.getString("CITY"));
        }
    }
}

The output for both will be identical, with the sample data I have, it is as follows..
SELECT * FROM EMPLOYEE WHERE CITY = 'Rotkreuz'
Koray Tugay Rotkreuz
 
SELECT * FROM EMPLOYEE WHERE CITY = 'Luzern'
Deniz Tugay Luzern
Toprak Tugay Luzern

Is it possible that what they mean is..
The PreparedStatement object instance is constructed once, allowing you to modify the parameters of the query without having to construct a new query string every time.
?