public.javadoc.org.spincast.plugins.jdbc.NamedParameterStatement.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
NamedParameterStatement (org.spincast:spincast-framework 1.13.0 API)
org.spincast.plugins.jdbc
Class NamedParameterStatement
- java.lang.Object
-
- org.spincast.plugins.jdbc.NamedParameterStatement
-
public class NamedParameterStatement
extends Object
- Author:
- adam_crume
http://www.javaworld.com/article/2077706/core-java/named-parameters-for-preparedstatement.html
-
-
Constructor Summary
Constructors
Constructor and Description
NamedParameterStatement(Connection connection,
String query)
Creates a NamedParameterStatement.
NamedParameterStatement(Connection connection,
String query,
int autoGeneratedKeys)
Spincast added
-
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
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.
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.
ResultSet
getGeneratedKeys()
Spincast added
PreparedStatement
getStatement()
Returns the underlying statement.
void
setBytes(String name,
byte[] value)
Added to the original code by Spincast.
void
setInt(String name,
int value)
Sets a parameter.
void
setLong(String name,
long value)
Sets a parameter.
void
setObject(String name,
Object value)
Sets a parameter.
void
setString(String name,
String value)
Sets a parameter.
void
setTimestamp(String name,
Timestamp value)
Sets a parameter.
-
-
Constructor Detail
-
NamedParameterStatement
public NamedParameterStatement(Connection connection,
String query)
throws SQLException
Creates a NamedParameterStatement. Wraps a call to
c.prepareStatement
.
- Parameters:
connection
- the database connection
query
- 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 Detail
-
setObject
public void setObject(String name,
Object value)
throws SQLException
Sets a parameter.
- Parameters:
name
- parameter name
value
- parameter value
- Throws:
SQLException
- if an error occurred
IllegalArgumentException
- if the parameter does not exist
- See Also:
PreparedStatement.setObject(int, java.lang.Object)
-
setString
public void setString(String name,
String value)
throws SQLException
Sets a parameter.
- Parameters:
name
- parameter name
value
- parameter value
- Throws:
SQLException
- if an error occurred
IllegalArgumentException
- if the parameter does not exist
- See Also:
PreparedStatement.setString(int, java.lang.String)
-
setInt
public void setInt(String name,
int value)
throws SQLException
Sets a parameter.
- Parameters:
name
- parameter name
value
- parameter value
- Throws:
SQLException
- if an error occurred
IllegalArgumentException
- if the parameter does not exist
- See Also:
PreparedStatement.setInt(int, int)
-
setLong
public void setLong(String name,
long value)
throws SQLException
Sets a parameter.
- Parameters:
name
- parameter name
value
- parameter value
- Throws:
SQLException
- if an error occurred
IllegalArgumentException
- if the parameter does not exist
- See Also:
PreparedStatement.setInt(int, int)
-
setTimestamp
public void setTimestamp(String name,
Timestamp value)
throws SQLException
Sets a parameter.
- Parameters:
name
- parameter name
value
- parameter value
- Throws:
SQLException
- if an error occurred
IllegalArgumentException
- if the parameter does not exist
- See Also:
PreparedStatement.setTimestamp(int, java.sql.Timestamp)
-
setBytes
public void setBytes(String name,
byte[] value)
throws SQLException
Added to the original code by Spincast.
- Throws:
SQLException
-
getStatement
public PreparedStatement getStatement()
Returns the underlying statement.
- Returns:
- the statement
-
execute
public boolean execute()
throws SQLException
Executes the statement.
- Returns:
- true if the first result is a
ResultSet
- Throws:
SQLException
- if an error occurred
- See Also:
PreparedStatement.execute()
-
executeQuery
public ResultSet executeQuery()
throws SQLException
Executes the statement, which must be a query.
- Returns:
- the query results
- Throws:
SQLException
- if an error occurred
- See Also:
PreparedStatement.executeQuery()
-
executeUpdate
public int executeUpdate()
throws 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:
SQLException
- if an error occurred
- See Also:
PreparedStatement.executeUpdate()
-
close
public void close()
throws SQLException
Closes the statement.
- Throws:
SQLException
- if an error occurred
- See Also:
Statement.close()
-
addBatch
public void addBatch()
throws SQLException
Adds the current set of parameters as a batch entry.
- Throws:
SQLException
- if something went wrong
-
executeBatch
public int[] executeBatch()
throws SQLException
Executes all of the batched statements.
See Statement.executeBatch()
for details.
- Returns:
- update counts for each statement
- Throws:
SQLException
- if something went wrong
-
getGeneratedKeys
public ResultSet getGeneratedKeys()
throws SQLException
Spincast added
- Throws:
SQLException
Copyright © 2019. All rights reserved.