Java Reference
In-Depth Information
try {
statement = obtainStatement();
Now, we enter a loop to execute the statement. This loop will execute until the statement
executes successfully.
for (;;) {
try {
The arguments are copied to the statement.
for (int i = 0; i < parameters.length; i++) {
if (parameters[i] == null) {
statement.setNull(i, Types.INTEGER);
} else {
statement.setObject(i + 1, parameters[i]);
}
}
The current time is taken before and after the SQL is executed. Adding a statement to log
this time can be helpful when tuning the SQL statements and queries.
long time = System.currentTimeMillis();
statement.execute();
time = System.currentTimeMillis() - time;
return;
If a SQLException is thrown while trying to execute the SQL statement, then the
connection is reopened and the SQL is tried again.
} catch (SQLException e) {
logger.log(Level.SEVERE, "SQL Exception", e);
if (!(e.getCause() instanceof SQLException)) {
this.manager.tryOpen();
} else {
throw (new WorkloadException(e));
}
}
}
} catch (SQLException e) {
throw (new WorkloadException(e));
} finally {
if (statement != null) {
releaseStatement(statement);
}
Once the SQL statement has been executed, the statement can be released.
The executeQuery function works almost identically to the execute method. The
only difference is that the executeQuery function returns a ResultSet .
Search WWH ::




Custom Search