Awake SQL v1.2.1

org.awakefw.sql.api.util
Class PreparedStatementRunner

java.lang.Object
  extended by org.awakefw.sql.api.util.PreparedStatementRunner

public class PreparedStatementRunner
extends Object

Wrapper class for all kind of prepared statement: query or update
Update and Delete are safe because the WHERE clause is mandatory to prevent dramatic errors.

Example:

 // Get a JDBC Connection
 Connection connection = ...
  
 int customerId = 1;
 String sql = "select * from customer where customer_id = 1";
  
 // Create the PreparedStatementRunner instance
 PreparedStatementRunner preparedStatementRunner = new PreparedStatementRunner(
        connection, sql, customerId);
  
 // Execute a query
 ResultSet rs = preparedStatementRunner.executeQuery();
 ...
 ...
 // close the underlying ResultSet and PreparedStatement
 preparedStatementRunner.close();
 

Since:
1.0 *

Constructor Summary
PreparedStatementRunner(Connection connection, String sql, Object... params)
          Constructor.
 
Method Summary
 void close()
          Closes the PreparedStatementRunner.
 ResultSet executeQuery()
          Executes a SQL prepared statement for a query.
 int executeUpdate()
          Executes a SQL prepared statement for an update.
 String getDevelopedQuery()
          Returns the developedQuery with substituted '?'
 String toString()
          Returns a clean representation of the PreparedStatementRunner instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PreparedStatementRunner

public PreparedStatementRunner(Connection connection,
                               String sql,
                               Object... params)
Constructor.

Parameters:
connection - the JDBC Connection instance
sql - the prepared statement base sql request with all the '?'
params - the prepared statement parameters value in the awaited order
Method Detail

close

public void close()
Closes the PreparedStatementRunner. This call is recommended. It will close the underlying prepared statement & result set.


executeQuery

public ResultSet executeQuery()
                       throws SQLException
Executes a SQL prepared statement for a query.

Returns:
the result set of the prepared statement
Throws:
SQLException - if a SQL Exception is raised

executeUpdate

public int executeUpdate()
                  throws SQLException
Executes a SQL prepared statement for an update.

Returns:
the return code oft he prepared statement
Throws:
SQLException - if a SQL Exception is raised

getDevelopedQuery

public String getDevelopedQuery()
Returns the developedQuery with substituted '?' by the passed values as parameters.

Returns:
the developedQuery with substituted '?' by the passed values as parameters

toString

public String toString()
Returns a clean representation of the PreparedStatementRunner instance.

Overrides:
toString in class Object
Returns:
a clean representation of the PreparedStatementRunner instance

Awake SQL v1.2.1

Awake SQL - Virtual JDBC Driver over HTTP for Android, Swing and JavaFX
Android & Desktop Edition allow easy access to majors remote SQL databases with regular JDBC calls:
DB2 - H2 - HSQLDB (HyperSQL) - Informix - Ingres - MySQL - Oracle - PostgreSQL - SQL Server - Sybase - Teradata
Copyright © 2012 Kawan Softwares SAS