Re: getUdateCount() vs. RETURNING clause

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: getUdateCount() vs. RETURNING clause
Дата
Msg-id hejdfj$3rs$1@ger.gmane.org
обсуждение исходный текст
Ответ на Re: getUdateCount() vs. RETURNING clause  (Oliver Jowett <oliver@opencloud.com>)
Список pgsql-jdbc
Oliver Jowett, 25.11.2009 14:42:
> You never call getMoreResults(), so you are only looking at a single
> result, which is either a resultset or an update count, never both.
[...]
Hmm, sorry I missed that in my initial email then. I did call getMoreResults()

The following still returns false for getMoreResults()

PreparedStatement pstmt = con.prepareStatement(update);
pstmt.setInt(1, 1);
boolean hasResult = pstmt.execute();

if (hasResult ) {
  ResultSet rs = pstmt.getResultSet();
  if (rs != null && rs.next()) {
    int newId = rs.getInt(1);
    System.out.println("newid: " + newId);
  }
}
boolean more = pstmt.getMoreResults(); // returns false

> You may have more success using something like this:
>
>>   PreparedStatement pstmt = con.prepareStatement("UPDATE something with no RETURNING clause", new String[] {
"some_column"}); 
>>   int updateCount = pstmt.executeUpdate();
>>   ResultSet results = pstmt.getGeneratedKeys();

That indeed works!

But I still think the behaviour with getMoreResults() is - at least - confusing ;)

Thanks a lot for all your patience!

Thomas


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Oliver Jowett
Дата:
Сообщение: Re: getUdateCount() vs. RETURNING clause
Следующее
От: Thomas Kellerer
Дата:
Сообщение: getTablePrivileges() does not report TRUNCATE privilege correctly