Re: JDBC3 and 7.4.1
От | Oliver Jowett |
---|---|
Тема | Re: JDBC3 and 7.4.1 |
Дата | |
Msg-id | 40369EFC.9000700@opencloud.com обсуждение исходный текст |
Ответ на | Re: JDBC3 and 7.4.1 (Ranjeet Kapur <ranjeet_kapur@yahoo.com>) |
Список | pgsql-jdbc |
Ranjeet Kapur wrote: > Thanks, I just did a few experiments and found the same thing, that > getFetchSize() was returning 0. Is there anything else I could use to > achieve the same result, namely how many rows in the select ?? I am very > new to DB programming that´s why I probably misread the documentation on > getFetchSize(). Add a COUNT(*) to the query, if you can; then the count will appear as a column in your resultset. Alternatively: Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query); // Count rows. rs.last(); int resultSetSize = rs.getRow(); // Process actual resultset rs.beforeFirst(); while (rs.next()) { // do stuff } but this requires iterating over the resultset twice, and using TYPE_SCROLL_INSENSITIVE prevents the current driver from using cursors to incrementally fetch data, so you will have the entire resultset in memory on the Java side. If you don't need the total count before processing the resultset, just count as you process each result row (then you don't need a TYPE_SCROLL_INSENSITIVE ResultSet, either). -O
В списке pgsql-jdbc по дате отправления: