Class JdbcTemplate
java.lang.Object
migratedb.v1.core.api.internal.jdbc.JdbcTemplate
- Direct Known Subclasses:
BigQueryJdbcTemplate,SpannerJdbcTemplate
Collection of utility methods for querying the DB. Inspired by Spring's JdbcTemplate.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConnectionThe DB connection to use.protected final intThe type to assign to a null value. -
Constructor Summary
ConstructorsConstructorDescriptionJdbcTemplate(Connection connection, DatabaseType databaseType) Creates a new JdbcTemplate. -
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes this sql statement using a PreparedStatement.executeStatement(String sql) Executes this sql statement using an ordinary Statement.voidextractErrors(Results results, SQLException e) protected PreparedStatementprepareStatement(String sql, Object[] params) Creates a new prepared statement for this sql with these params.<T> List<T>Executes this query and map the results using this row mapper.booleanqueryForBoolean(String query, String... params) Executes this query with these parameters against this connection.intqueryForInt(String query, String... params) Executes this query with these parameters against this connection.queryForList(String query, Object... params) Executes this query with these parameters against this connection.queryForString(String query, String... params) Executes this query with these parameters against this connection.queryForStringList(String query, String... params) Executes this query with these parameters against this connection.voidExecutes this update sql statement.
-
Field Details
-
connection
The DB connection to use. -
nullType
protected final int nullTypeThe type to assign to a null value.
-
-
Constructor Details
-
JdbcTemplate
Creates a new JdbcTemplate.- Parameters:
connection- The database connection to use.
-
-
Method Details
-
getConnection
- Returns:
- The DB connection to use.
-
queryForList
Executes this query with these parameters against this connection.- Parameters:
query- The query to execute.params- The query parameters.- Returns:
- The query results.
- Throws:
SQLException- when the query execution failed.
-
queryForStringList
Executes this query with these parameters against this connection.- Parameters:
query- The query to execute.params- The query parameters.- Returns:
- The query results as a list of strings.
- Throws:
SQLException- when the query execution failed.
-
queryForInt
Executes this query with these parameters against this connection.- Parameters:
query- The query to execute.params- The query parameters.- Returns:
- The query result.
- Throws:
SQLException- when the query execution failed.
-
queryForBoolean
Executes this query with these parameters against this connection.- Parameters:
query- The query to execute.params- The query parameters.- Returns:
- The query result.
- Throws:
SQLException- when the query execution failed.
-
queryForString
Executes this query with these parameters against this connection.- Parameters:
query- The query to execute.params- The query parameters.- Returns:
- The query result.
- Throws:
SQLException- when the query execution failed.
-
execute
Executes this sql statement using a PreparedStatement.- Parameters:
sql- The statement to execute.params- The statement parameters.- Throws:
SQLException- when the execution failed.
-
executeStatement
Executes this sql statement using an ordinary Statement.- Parameters:
sql- The statement to execute.- Returns:
- the results of the execution.
-
extractErrors
-
update
Executes this update sql statement.- Parameters:
sql- The statement to execute.params- The statement parameters.- Throws:
SQLException- when the execution failed.
-
prepareStatement
Creates a new prepared statement for this sql with these params.- Parameters:
sql- The sql to execute.params- The params.- Returns:
- The new prepared statement.
- Throws:
SQLException- when the statement could not be prepared.
-
query
Executes this query and map the results using this row mapper.- Type Parameters:
T- The type of the result objects.- Parameters:
sql- The query to execute.rowMapper- The row mapper to use.- Returns:
- The list of results.
- Throws:
SQLException- when the query failed to execute.
-