java - Invalid operation for read only resultset when using select for update nowait in multithreaded environment -


for oracle database, following program throw sql exceptions threads. why downgrading resultsetconcurrency concur_updatable concur_read_only? in single thread environment not happening.

import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception;   public class main extends thread {      public static final string dburl = "jdbc:oracle:thin:@localhost:1521:db";     public static final string dbuser = "user";     public static final string dbpass = "pass";      public static void main(string[] args) {         // todo auto-generated method stub         for(int i=0; i<20; i++)             new main().start();     }      @override     public void run() {          try         {             drivermanager.registerdriver(new oracle.jdbc.driver.oracledriver());              connection con = drivermanager.getconnection(dburl, dbuser, dbpass);             con.setautocommit(false);              try(preparedstatement pstmt = con.preparestatement("select column1 table1 update nowait",                      resultset.type_forward_only, resultset.concur_updatable))             {                                resultset rs = pstmt.executequery();                  if (rs.next()) {                     rs.updatestring(1, "12345");                     rs.updaterow();                 }                         }                         {                 con.commit();                 con.close();             }         }         catch(sqlexception e)         {             if(!e.tostring().contains("nowait"))                 e.printstacktrace();         }     }  } 

you can @ warnings raised against result set/statement/connection see why downgraded. added after executequery() call:

sqlwarning warning = pstmt.getwarnings(); while (warning != null) {     system.out.println("warning: " + warning.getsqlstate()         + ": " + warning.geterrorcode());     system.out.println(warning.getmessage());     warning = warning.getnextwarning(); } 

in case you'll see:

warning: 99999: 17091
warning: unable create resultset @ requested type and/or concurrency level: ora-00054: resource busy , acquire nowait specified or timeout expired

you're looking nowait exception, you're getting warning. isn't clear me why still result set in scenario; can @ least trap warning , not go result set loop if see it.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -