pgsql-sql-owner

Поиск
Список
Период
Сортировка
От ALMA TAHIR
Тема pgsql-sql-owner
Дата
Msg-id 1393911490.4808.YahooMailNeo@web192701.mail.sg3.yahoo.com
обсуждение исходный текст
Список pgsql-sql
Hi,

I am using below code in multi threaded environment, but when multiple threads are accessing then i get : "org.postgresql.util.PSQLException: ERROR: tuple concurrently updated" exception. But my concern is I need to use it in multi threaded env, for the same reason I am using FOR UPDATE with cursor. Then where is the issue??? Am I missing something????? Please help me with the same.....
        Statement stmt = c.createStatement();
          // Setup function to call.
          stmt.execute("CREATE OR REPLACE FUNCTION refcursorfunc() RETURNS refcursor AS '"
                                          + " DECLARE "
                                          + "    call_log_rec call_log % rowtype; "
                                          + "             call_log_cursor refcursor; "
                                          + " final_cursor refcursor; "
                                          + " idInt int[]; "
                                          + " BEGIN "
                                          + "    OPEN call_log_cursor FOR SELECT * FROM call_log WHERE aht_read_status = 0 ORDER BY record_sequence_number ASC limit 20 FOR UPDATE; "
                                          + " LOOP "
                                          + " FETCH NEXT FROM call_log_cursor INTO call_log_rec; "
                                          + " EXIT WHEN call_log_rec IS NULL; "
                                          + " UPDATE call_log SET aht_read_status = 1 WHERE CURRENT OF call_log_cursor; "
                                          + " idInt := idInt || ARRAY [call_log_rec.record_sequence_number]; "
                                          + " END LOOP;"
                                          + " OPEN final_cursor FOR SELECT record_sequence_number FROM call_log WHERE record_sequence_number  = ANY(idInt); "
                                          + "    RETURN final_cursor; "
                                          + " END;' language plpgsql");
          stmt.close();
          // We must be inside a transaction for cursors to work.
          c.setAutoCommit(false);

          // Procedure call.
          CallableStatement proc = c.prepareCall("{ ? = call refcursorfunc() }");
          proc.registerOutParameter(1, Types.OTHER);
          System.out.println("BEFORE::: Thread name::: " + Thread.currentThread().getName());
          proc.execute();
         
          ResultSet results = (ResultSet) proc.getObject(1);
          while (results.next()) {
              // do something with the results...
                          System.out.println("Hurrey got the results from SP........");
                          System.out.println("AFTER::::Thread name::: " + Thread.currentThread().getName()+ " record_sequence_number:::: "+results.getString(1));
          }
          c.commit();
          results.close();
          proc.close();

Thanks in advance Alma

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

Предыдущее
От: ALMA TAHIR
Дата:
Сообщение: Re: pgsql-sq-owner
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: pgsql-sq-owner