I tried to get some data using the sql.rows () method of Groovy and it took a very long time to return the values.
So, I tried the "standard" method and much faster ( 150 times faster ).
What am I missing?
Look at the following code: the first method returns results in about 2500 ms, and the second - after 15 ms!
class MyService { javax.sql.DataSource dataSource def SQL_QUERY = "select M_FIRSTNAME as firstname, M_LASTNAME as lastname, M_NATIONALITY as country from CT_PLAYER order by M_ID asc"; def getPlayers1(int offset, int maxRows) { def t = System.currentTimeMillis() def sql = new Sql(dataSource) def rows = sql.rows(SQL_QUERY, offset, maxRows) println "time1 : ${System.currentTimeMillis()-t}" return rows } def getPlayers2(int offset, int maxRows) { def t = System.currentTimeMillis(); Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); statement.setMaxRows(offset + maxRows -1); ResultSet resultSet = statement.executeQuery(SQL_QUERY); def l_list =[]; if(resultSet.absolute(offset)) { while (true) { l_list << [ 'firstname':resultSet.getString('firstname'), 'lastname' :resultSet.getString('lastname'), 'country' :resultSet.getString('country') ]; if(!resultSet.next()) break; } } resultSet.close() statement.close() connection.close() println "time2 : ${System.currentTimeMillis()-t}" return l_list }
source share