类 JdbcTestUtils

    • 方法详细资料

      • countRowsInTable

        public static int countRowsInTable​(JdbcTemplate jdbcTemplate,
                                           String tableName)
        Count the rows in the given table.
        参数:
        jdbcTemplate - the JdbcTemplate with which to perform JDBC operations
        tableName - name of the table to count rows in
        返回:
        the number of rows in the table
      • countRowsInTableWhere

        public static int countRowsInTableWhere​(JdbcTemplate jdbcTemplate,
                                                String tableName,
                                                String whereClause)
        Count the rows in the given table, using the provided WHERE clause.

        If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated SELECT statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "SELECT COUNT(0) FROM person WHERE name = 'Bob' and age > 25".

        参数:
        jdbcTemplate - the JdbcTemplate with which to perform JDBC operations
        tableName - the name of the table to count rows in
        whereClause - the WHERE clause to append to the query
        返回:
        the number of rows in the table that match the provided WHERE clause
      • deleteFromTables

        public static int deleteFromTables​(JdbcTemplate jdbcTemplate,
                                           String... tableNames)
        Delete all rows from the specified tables.
        参数:
        jdbcTemplate - the JdbcTemplate with which to perform JDBC operations
        tableNames - the names of the tables to delete from
        返回:
        the total number of rows deleted from all specified tables
      • deleteFromTableWhere

        public static int deleteFromTableWhere​(JdbcTemplate jdbcTemplate,
                                               String tableName,
                                               String whereClause,
                                               Object... args)
        Delete rows from the given table, using the provided WHERE clause.

        If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated DELETE statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "DELETE FROM person WHERE name = 'Bob' and age > 25".

        As an alternative to hard-coded values, the "?" placeholder can be used within the WHERE clause, binding to the given arguments.

        参数:
        jdbcTemplate - the JdbcTemplate with which to perform JDBC operations
        tableName - the name of the table to delete rows from
        whereClause - the WHERE clause to append to the query
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale.
        返回:
        the number of rows deleted from the table
      • dropTables

        public static void dropTables​(JdbcTemplate jdbcTemplate,
                                      String... tableNames)
        Drop the specified tables.
        参数:
        jdbcTemplate - the JdbcTemplate with which to perform JDBC operations
        tableNames - the names of the tables to drop
      • readScript

        @Deprecated
        public static String readScript​(LineNumberReader lineNumberReader,
                                        String commentPrefix)
                                 throws IOException
        已过时。
        as of Spring 4.0.3, in favor of using ScriptUtils.readScript(LineNumberReader, String, String)
        Read a script from the provided LineNumberReader, using the supplied comment prefix, and build a String containing the lines.

        Lines beginning with the comment prefix are excluded from the results; however, line comments anywhere else — for example, within a statement — will be included in the results.

        参数:
        lineNumberReader - the LineNumberReader containing the script to be processed
        commentPrefix - the prefix that identifies comments in the SQL script — typically "--"
        返回:
        a String containing the script lines
        抛出:
        IOException
      • splitSqlScript

        @Deprecated
        public static void splitSqlScript​(String script,
                                          char delim,
                                          List<String> statements)
        已过时。
        as of Spring 4.0.3, in favor of using ScriptUtils.splitSqlScript(String, char, List)
        Split an SQL script into separate statements delimited by the provided delimiter character. Each individual statement will be added to the provided List.

        Within a statement, "--" will be used as the comment prefix; any text beginning with the comment prefix and extending to the end of the line will be omitted from the statement. In addition, multiple adjacent whitespace characters will be collapsed into a single space.

        参数:
        script - the SQL script
        delim - character delimiting each statement — typically a ';' character
        statements - the list that will contain the individual statements