org.pf.db.util
Class SQLExecutor

java.lang.Object
  extended by org.pf.db.util.SQLExecutor

public class SQLExecutor
extends Object

Provides an easy to use interface to execute SQL statements against a database.

Version:
1.1
Author:
Manfred Duchrow

Constructor Summary
SQLExecutor(DataSource aDataSource)
          Initialize the new instance with default values.
 
Method Summary
 void close()
          Closes all open connections.
 void closeStatement(Statement statement)
          Closes the given statement.
 int execute(String sql)
          Executes the given SQL command and returns the number of affected rows.
 boolean executeSQL(String sql)
          Executes the given SQL command and returns true if the execution was successful.
 int executeWriteStatement(PreparedStatement statement)
          Executes the given statement and returns the number of affected rows.
 PreparedStatement prepareWriteStatement(String sql)
          Returns a PreparedStatement for the given SQL command.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLExecutor

public SQLExecutor(DataSource aDataSource)
Initialize the new instance with default values.

Parameters:
aDataSource - The datasource the executor should connect to (must not be null)
Method Detail

prepareWriteStatement

public PreparedStatement prepareWriteStatement(String sql)
                                        throws SQLException
Returns a PreparedStatement for the given SQL command.

Parameters:
sql - A valid SQL statement with placeholders (?) (no SELECT allowed here!)
Throws:
SQLException - Any problem that occurs during execution

executeWriteStatement

public int executeWriteStatement(PreparedStatement statement)
                          throws SQLException
Executes the given statement and returns the number of affected rows.

Parameters:
statement - A valid statement, created before by this executor
Throws:
SQLException - Any problem that occurs during execution

execute

public int execute(String sql)
            throws SQLException
Executes the given SQL command and returns the number of affected rows.

Parameters:
sql - A valid SQL statement (no SELECT allowed here!)
Throws:
SQLException - Any problem that occurs during execution

executeSQL

public boolean executeSQL(String sql)
Executes the given SQL command and returns true if the execution was successful.

Parameters:
sql - A valid SQL statement (no SELECT allowed here!)

close

public void close()
Closes all open connections. Connections will be reopened automatically if necessary.


closeStatement

public void closeStatement(Statement statement)
Closes the given statement.



Copyright © 2014 Manfred Duchrow Consulting & Software. All rights reserved.