cluster5.server.datastorage
Class NamedParameterStatement

java.lang.Object
  extended by cluster5.server.datastorage.NamedParameterStatement

public class NamedParameterStatement
extends java.lang.Object

http://www.java2s.com/Article/Java/Database-JDBC/Named_Parameters_for_PreparedStatement .htm

Author:
adam_crume, ibisek (mostly Java 1.5 modifications)

Constructor Summary
NamedParameterStatement(java.sql.Connection connection, java.lang.String query)
          Creates a NamedParameterStatement.
 
Method Summary
 void addBatch()
          Adds the current set of parameters as a batch entry.
 void close()
          Closes the statement.
 boolean execute()
          Executes the statement.
 int[] executeBatch()
          Executes all of the batched statements.
 java.sql.ResultSet executeQuery()
          Executes the statement, which must be a query.
 int executeUpdate()
          Executes the statement, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.
 java.sql.PreparedStatement getStatement()
          Returns the underlying statement.
 void setBoolean(java.lang.String name, boolean value)
          Sets a parameter.
 void setBytes(java.lang.String name, byte[] value)
          Sets a parameter.
 void setDate(java.lang.String name, java.util.Date date)
          Sets a parameter.
 void setInt(java.lang.String name, int value)
          Sets a parameter.
 void setLong(java.lang.String name, java.lang.Long value)
          Sets a parameter.
 void setObject(java.lang.String name, java.lang.Object value)
          Sets a parameter.
 void setString(java.lang.String name, java.lang.String value)
          Sets a parameter.
 void setTimestamp(java.lang.String name, java.sql.Timestamp value)
          Sets a parameter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamedParameterStatement

public NamedParameterStatement(java.sql.Connection connection,
                               java.lang.String query)
                        throws java.sql.SQLException
Creates a NamedParameterStatement. Wraps a call to c. prepareStatement.

Parameters:
connection - the database connection
query - the parameterized query
Throws:
java.sql.SQLException - if the statement could not be created
Method Detail

setObject

public void setObject(java.lang.String name,
                      java.lang.Object value)
               throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setObject(int, java.lang.Object)

setString

public void setString(java.lang.String name,
                      java.lang.String value)
               throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setString(int, java.lang.String)

setDate

public void setDate(java.lang.String name,
                    java.util.Date date)
             throws java.sql.SQLException
Sets a parameter.

Parameters:
name -
date -
Throws:
java.sql.SQLException

setInt

public void setInt(java.lang.String name,
                   int value)
            throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setInt(int, int)

setLong

public void setLong(java.lang.String name,
                    java.lang.Long value)
             throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setInt(int, int)

setTimestamp

public void setTimestamp(java.lang.String name,
                         java.sql.Timestamp value)
                  throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setTimestamp(int, java.sql.Timestamp)

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
                throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setInt(int, int)

setBytes

public void setBytes(java.lang.String name,
                     byte[] value)
              throws java.sql.SQLException
Sets a parameter.

Parameters:
name - parameter name
value - parameter value
Throws:
java.sql.SQLException - if an error occurred
java.lang.IllegalArgumentException - if the parameter does not exist
See Also:
PreparedStatement.setInt(int, int)

getStatement

public java.sql.PreparedStatement getStatement()
Returns the underlying statement.

Returns:
the statement

execute

public boolean execute()
                throws java.sql.SQLException
Executes the statement.

Returns:
true if the first result is a ResultSet
Throws:
java.sql.SQLException - if an error occurred
See Also:
PreparedStatement.execute()

executeQuery

public java.sql.ResultSet executeQuery()
                                throws java.sql.SQLException
Executes the statement, which must be a query.

Returns:
the query results
Throws:
java.sql.SQLException - if an error occurred
See Also:
PreparedStatement.executeQuery()

executeUpdate

public int executeUpdate()
                  throws java.sql.SQLException
Executes the statement, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.

Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurred
See Also:
PreparedStatement.executeUpdate()

close

public void close()
           throws java.sql.SQLException
Closes the statement.

Throws:
java.sql.SQLException - if an error occurred
See Also:
Statement.close()

addBatch

public void addBatch()
              throws java.sql.SQLException
Adds the current set of parameters as a batch entry.

Throws:
java.sql.SQLException - if something went wrong

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Executes all of the batched statements. See Statement.executeBatch() for details.

Returns:
update counts for each statement
Throws:
java.sql.SQLException - if something went wrong