Package org.spincast.plugins.jdbc
Class NamedParameterStatement
java.lang.Object
org.spincast.plugins.jdbc.NamedParameterStatement
- Author:
- adam_crume http://www.javaworld.com/article/2077706/core-java/named-parameters-for-preparedstatement.html
-
Constructor Summary
ConstructorsConstructorDescriptionNamedParameterStatement(Connection connection, String query) Creates a NamedParameterStatement.NamedParameterStatement(Connection connection, String query, int autoGeneratedKeys) Spincast added -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()Adds the current set of parameters as a batch entry.voidclose()Closes the statement.booleanexecute()Executes the statement.int[]Executes all of the batched statements.Executes the statement, which must be a query.intExecutes the statement, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.Spincast addedReturns the underlying statement.voidAdded to the original code by Spincast.voidSets a parameter.voidSets a parameter.voidSets a parameter.voidSets a parameter.voidsetTimestamp(String name, Timestamp value) Sets a parameter.
-
Constructor Details
-
NamedParameterStatement
Creates a NamedParameterStatement. Wraps a call to c.prepareStatement.- Parameters:
connection- the database connectionquery- the parameterized query- Throws:
SQLException- if the statement could not be created
-
NamedParameterStatement
public NamedParameterStatement(Connection connection, String query, int autoGeneratedKeys) throws SQLException Spincast added- Throws:
SQLException
-
-
Method Details
-
setObject
Sets a parameter.- Parameters:
name- parameter namevalue- parameter value- Throws:
SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
-
setString
Sets a parameter.- Parameters:
name- parameter namevalue- parameter value- Throws:
SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
-
setInt
Sets a parameter.- Parameters:
name- parameter namevalue- parameter value- Throws:
SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
-
setLong
Sets a parameter.- Parameters:
name- parameter namevalue- parameter value- Throws:
SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
-
setTimestamp
Sets a parameter.- Parameters:
name- parameter namevalue- parameter value- Throws:
SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
-
setBytes
Added to the original code by Spincast.- Throws:
SQLException
-
getStatement
Returns the underlying statement.- Returns:
- the statement
-
execute
Executes the statement.- Returns:
- true if the first result is a
ResultSet - Throws:
SQLException- if an error occurred- See Also:
-
executeQuery
Executes the statement, which must be a query.- Returns:
- the query results
- Throws:
SQLException- if an error occurred- See Also:
-
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.- Returns:
- number of rows affected
- Throws:
SQLException- if an error occurred- See Also:
-
close
Closes the statement.- Throws:
SQLException- if an error occurred- See Also:
-
addBatch
Adds the current set of parameters as a batch entry.- Throws:
SQLException- if something went wrong
-
executeBatch
Executes all of the batched statements. SeeStatement.executeBatch()for details.- Returns:
- update counts for each statement
- Throws:
SQLException- if something went wrong
-
getGeneratedKeys
Spincast added- Throws:
SQLException
-