postgresql - Creating list with spring ResultSet -


i need create list of contacts using resultset , java 8.

i need filter list name, if name suitable add list. , set fetchsize work million rows postgres.

for example:

public list <contact> getall (string namefilter) {         pattern pattern = pattern.compile (namefilter);          list <contact> contacts = new arraylist <> ();          jdbctemplate.query ("select * contacts", rs -> { // here necessary maybe !pattern.matcher(name).matches() // , maybe jdbctemplate.setfetchsize (*how many rows better read // postgres? (5,5000,50000 ???) *)             contacts.add (new contact (rs.getint ("id"), rs.getstring ("name")));         });          return contacts;      } 

how can this?

you need set fetch size before running query. bear in mind if use singleton jdbctemplate object going affect queries, , should set configuration when jdbctemplate object created.

about creating list, using functional interface resultsetextractor, should work:

springjdbctemplate.query ("select * contacts", rs -> {   while(rs.next()) {     if (pattern.matcher(rs.getstring("name")).matches())       contacts.add (new contact (rs.getint ("id"), rs.getstring ("name")));   }   return null; }); 

it suffices if translate pattern sql query faster.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -