0

I have very limited knowledge of database in general. I am flummoxed by how exactly JDBC(Presto) works - so in my program, I have something like

ResultSet rs = statement.execute(sqlcommand);
while (rs.next()) {...}

the execute part takes a few seconds but rs.next() takes forever and usually times out without being able to return even 1 record. I used to think that execute executes the query and fetches the result, but now it looks to me that the actually result won't be computed until rs.next()

Anyone here with a good understanding of how exactly JDBC works? And is there a way to optimize rs.next() so it will at least return something during a reasonable time frame?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
camus
  • 57
  • 1
  • 8
  • JDBC doesn't execute the query, the dbms does. When? It depends on which dbms you're using. – jarlh Oct 27 '21 at 14:04
  • @jarlh Thanks for the information jarlh. I think my question would be when are the results brought back - after execute or along with rs.next() – camus Oct 27 '21 at 14:19
  • @camus Again, that depends on the DBMS and the driver implementation (and sometimes on configuration, whether or not it is in auto-commit mode or not, result set updatability and scrollability, etc). I don't know Presto, but judging by the fact you mention `next()` seems slow, it is likely fetching rows on next(), which might mean that the DBMS is materializing rows on next(). Given it times out, it could also mean that you're trying to fetch a record that is locked, or something like that. – Mark Rotteveel Oct 28 '21 at 08:19

0 Answers0