Secure ResultSet Data Stream

Is ResultSet Thread Safe?

My question arises because in my program I used a different operator for each request, I declared ResultSet as a local variable, but this gives me an Operation error that is not resolved after closing the ResultSet. But my statements work as I use instructions in inserting and deleting a query. I commented on the ResultSet part and did not get an error!

+3
source share
3 answers

The real problem is that you are sharing Statement objects between multiple threads. Each time you execute the "Statement", the previously returned ResultSet is automatically closed. In this case, the ResultSet objects β€œbelong” to another thread that may not have finished using it yet. Hence the exception ...

You cannot pass Connection, Statement / PreparedStatement, or ResultSet objects between multiple threads. Each thread must acquire and release its own resources.

+6
source

No, a ResultSet should not be exposed to more than one thread.

ResultSet , : , ResultSet ResultSet , .

ResultSet finally try/catch.

. , . , . :

  • Sun Java. , , , - . "doComms" "savetodatabase" " ".
  • . "doComms" - .
  • / . .
  • Java - - ; . "insert studentinfo", , Student.
  • JDBC- .

- ? , ? - , ​​.

+4

, JDBC , . , , Spring JDBC. spring, DataSource spring JdbcTemplate.

JDBC, - .

+2
source

Source: https://habr.com/ru/post/1744608/


All Articles