Class FieldNamedPreparedStatementImpl
- java.lang.Object
-
- org.apache.flink.connector.jdbc.statement.FieldNamedPreparedStatementImpl
-
- All Implemented Interfaces:
AutoCloseable,FieldNamedPreparedStatement
public class FieldNamedPreparedStatementImpl extends Object implements FieldNamedPreparedStatement
Simple implementation ofFieldNamedPreparedStatement.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch()Adds a set of parameters to thisNamedPreparedStatementobject's batch of commands.voidclearParameters()Clears the current parameter values immediately.voidclose()Releases thisStatementobject's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.int[]executeBatch()Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.ResultSetexecuteQuery()Executes the SQL query in thisNamedPreparedStatementobject and returns theResultSetobject generated by the query.static StringparseNamedStatement(String sql, Map<String,List<Integer>> paramMap)Parses a sql with named parameters.static FieldNamedPreparedStatementprepareStatement(Connection connection, String sql, String[] fieldNames)Creates aNamedPreparedStatementobject for sending parameterized SQL statements to the database.voidsetBigDecimal(int fieldIndex, BigDecimal x)Sets the designated parameter to the givenjava.math.BigDecimalvalue.voidsetBoolean(int fieldIndex, boolean x)Sets the designated parameter to the given Javabooleanvalue.voidsetByte(int fieldIndex, byte x)Sets the designated parameter to the given Javabytevalue.voidsetBytes(int fieldIndex, byte[] x)Sets the designated parameter to the given Java array of bytes.voidsetDate(int fieldIndex, Date x)Sets the designated parameter to the givenjava.sql.Datevalue using the default time zone of the virtual machine that is running the application.voidsetDouble(int fieldIndex, double x)Sets the designated parameter to the given Javadoublevalue.voidsetFloat(int fieldIndex, float x)Sets the designated parameter to the given Javafloatvalue.voidsetInt(int fieldIndex, int x)Sets the designated parameter to the given Javaintvalue.voidsetLong(int fieldIndex, long x)Sets the designated parameter to the given Javalongvalue.voidsetNull(int fieldIndex, int sqlType)Sets the designated parameter to SQLNULL.voidsetObject(int fieldIndex, Object x)Sets the value of the designated parameter using the given object.voidsetShort(int fieldIndex, short x)Sets the designated parameter to the given Javashortvalue.voidsetString(int fieldIndex, String x)Sets the designated parameter to the given JavaStringvalue.voidsetTime(int fieldIndex, Time x)Sets the designated parameter to the givenjava.sql.Timevalue.voidsetTimestamp(int fieldIndex, Timestamp x)Sets the designated parameter to the givenjava.sql.Timestampvalue.
-
-
-
Method Detail
-
clearParameters
public void clearParameters() throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementClears the current parameter values immediately.In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method
clearParameters.- Specified by:
clearParametersin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.clearParameters()
-
executeQuery
public ResultSet executeQuery() throws SQLException
Description copied from interface:FieldNamedPreparedStatementExecutes the SQL query in thisNamedPreparedStatementobject and returns theResultSetobject generated by the query.- Specified by:
executeQueryin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.executeQuery()
-
addBatch
public void addBatch() throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementAdds a set of parameters to thisNamedPreparedStatementobject's batch of commands.- Specified by:
addBatchin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.addBatch()
-
executeBatch
public int[] executeBatch() throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSubmits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. Theintelements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch.- Specified by:
executeBatchin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
Statement.executeBatch()
-
setNull
public void setNull(int fieldIndex, int sqlType) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to SQLNULL.Note: You must specify the parameter's SQL type.
- Specified by:
setNullin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setNull(int, int)
-
setBoolean
public void setBoolean(int fieldIndex, boolean x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javabooleanvalue. The driver converts this to an SQLBITorBOOLEANvalue when it sends it to the database.- Specified by:
setBooleanin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setBoolean(int, boolean)
-
setByte
public void setByte(int fieldIndex, byte x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javabytevalue. The driver converts this to an SQLTINYINTvalue when it sends it to the database.- Specified by:
setBytein interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setByte(int, byte)
-
setShort
public void setShort(int fieldIndex, short x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javashortvalue. The driver converts this to an SQLSMALLINTvalue when it sends it to the database.- Specified by:
setShortin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setShort(int, short)
-
setInt
public void setInt(int fieldIndex, int x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javaintvalue. The driver converts this to an SQLINTEGERvalue when it sends it to the database.- Specified by:
setIntin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setInt(int, int)
-
setLong
public void setLong(int fieldIndex, long x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javalongvalue. The driver converts this to an SQLBIGINTvalue when it sends it to the database.- Specified by:
setLongin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setLong(int, long)
-
setFloat
public void setFloat(int fieldIndex, float x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javafloatvalue. The driver converts this to an SQLREALvalue when it sends it to the database.- Specified by:
setFloatin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setFloat(int, float)
-
setDouble
public void setDouble(int fieldIndex, double x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Javadoublevalue. The driver converts this to an SQLDOUBLEvalue when it sends it to the database.- Specified by:
setDoublein interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setDouble(int, double)
-
setBigDecimal
public void setBigDecimal(int fieldIndex, BigDecimal x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the givenjava.math.BigDecimalvalue. The driver converts this to an SQLNUMERICvalue when it sends it to the database.- Specified by:
setBigDecimalin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setBigDecimal(int, BigDecimal)
-
setString
public void setString(int fieldIndex, String x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given JavaStringvalue. The driver converts this to an SQLVARCHARorLONGVARCHARvalue (depending on the argument's size relative to the driver's limits onVARCHARvalues) when it sends it to the database.- Specified by:
setStringin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setString(int, String)
-
setBytes
public void setBytes(int fieldIndex, byte[] x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the given Java array of bytes. The driver converts this to an SQLVARBINARYorLONGVARBINARY(depending on the argument's size relative to the driver's limits onVARBINARYvalues) when it sends it to the database.- Specified by:
setBytesin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setBytes(int, byte[])
-
setDate
public void setDate(int fieldIndex, Date x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the givenjava.sql.Datevalue using the default time zone of the virtual machine that is running the application. The driver converts this to an SQLDATEvalue when it sends it to the database.- Specified by:
setDatein interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setDate(int, Date)
-
setTime
public void setTime(int fieldIndex, Time x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the givenjava.sql.Timevalue. The driver converts this to an SQLTIMEvalue when it sends it to the database.- Specified by:
setTimein interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setTime(int, Time)
-
setTimestamp
public void setTimestamp(int fieldIndex, Timestamp x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the designated parameter to the givenjava.sql.Timestampvalue. The driver converts this to an SQLTIMESTAMPvalue when it sends it to the database.- Specified by:
setTimestampin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setTimestamp(int, Timestamp)
-
setObject
public void setObject(int fieldIndex, Object x) throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementSets the value of the designated parameter using the given object.- Specified by:
setObjectin interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
PreparedStatement.setObject(int, Object)
-
close
public void close() throws SQLExceptionDescription copied from interface:FieldNamedPreparedStatementReleases thisStatementobject's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFieldNamedPreparedStatement- Throws:
SQLException- See Also:
Statement.close()
-
prepareStatement
public static FieldNamedPreparedStatement prepareStatement(Connection connection, String sql, String[] fieldNames) throws SQLException
Description copied from interface:FieldNamedPreparedStatementCreates aNamedPreparedStatementobject for sending parameterized SQL statements to the database.- Parameters:
connection- the connection used to connect to database.sql- an SQL statement that may contain one or more ':fieldName' as parameter placeholdersfieldNames- the field names in schema order used as the parameter names- Throws:
SQLException
-
parseNamedStatement
public static String parseNamedStatement(String sql, Map<String,List<Integer>> paramMap)
Parses a sql with named parameters. The parameter-index mappings are put into the map, and the parsed sql is returned.- Parameters:
sql- sql to parseparamMap- map to hold parameter-index mappings- Returns:
- the parsed sql
-
-