java - Is there a limit on the number of open JDBC ResultSets? -
i'm using jdbc mysql, , i'm wondering whether there limit on number of resultset objects can open @ given time. wasn't able find answer anywhere else on or in documentation.
i'm asking because program can potentially generate , manipulate high number of these resultsets, , i'm afraid of consequences have. alternative create set of classes mimics resultset methods need, require such class every table in database (and have many of them).
each resultset
belongs statement
, , each statement
associated database cursor, limited resource in databases. mysql doesn't have upper limit, having many open cursors affect database performance
you don't have close resultset
s (for example closed , reopened if re-execute statement) must close statement
s or leak database resources.
from resultset
documentation:
a resultset object automatically closed when statement object generated closed, re-executed, or used retrieve next result sequence of multiple results.
some databases oracle return errors such ora-01000: many open cursors
once exceed (configurable) per-session limit.
in general, should close statement
s possible. using java 7's try-with-resources convenient:
try (final statement s = conn.createstatement()) { final resultset rs = s.executequery(sql); while (rs.next()) { // process each row of result } } // statement auto-closed
if repeating same query multiple times query parameters vary, use preparedstatement
.
Comments
Post a Comment