public class SQLExecutor
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
SQLExecutor(javax.sql.DataSource aDataSource)
Initialize the new instance with default values.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes all open connections.
|
boolean |
closeStatement(java.sql.Statement statement)
Closes the given statement.
|
void |
commit()
Commit the last transaction.
|
protected java.sql.Connection |
connection() |
protected void |
connection(java.sql.Connection newValue) |
int |
execute(java.lang.String sql)
Executes the given SQL command and returns the number of affected rows.
|
boolean |
executeSQL(java.lang.String sql)
Executes the given SQL command and returns true if the execution was
successful.
|
int |
executeWriteStatement(java.sql.PreparedStatement statement)
Executes the given statement and returns the number of affected rows.
|
protected java.sql.Connection |
getConnection() |
protected javax.sql.DataSource |
getDataSource() |
protected boolean |
isClosed() |
protected java.sql.Connection |
newConnection() |
java.sql.PreparedStatement |
prepareWriteStatement(java.lang.String sql)
Returns a PreparedStatement for the given SQL command.
|
protected void |
setDataSource(javax.sql.DataSource newValue) |
public SQLExecutor(javax.sql.DataSource aDataSource)
aDataSource
- The datasource the executor should connect to (must not be null)public java.sql.PreparedStatement prepareWriteStatement(java.lang.String sql) throws java.sql.SQLException
sql
- A valid SQL statement with placeholders (?) (no SELECT allowed here!)java.sql.SQLException
- Any problem that occurs during executionpublic int executeWriteStatement(java.sql.PreparedStatement statement) throws java.sql.SQLException
statement
- A valid statement, created before by this executorjava.sql.SQLException
- Any problem that occurs during executionpublic int execute(java.lang.String sql) throws java.sql.SQLException
sql
- A valid SQL statement (no SELECT allowed here!)java.sql.SQLException
- Any problem that occurs during executionpublic boolean executeSQL(java.lang.String sql)
sql
- A valid SQL statement (no SELECT allowed here!)public void commit()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public boolean closeStatement(java.sql.Statement statement)
protected java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException
protected java.sql.Connection newConnection() throws java.sql.SQLException
java.sql.SQLException
protected boolean isClosed()
protected javax.sql.DataSource getDataSource()
protected void setDataSource(javax.sql.DataSource newValue)
protected java.sql.Connection connection()
protected void connection(java.sql.Connection newValue)