Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IS ResultSet thread safe

Is ResultSet Thread safe?

My question arises because in my program i have used different statement for each query i have declared a ResultSet as an local variable but it gives me a error of Operation not allowed after ResultSet is closed. But my statements are working as i'm using the statements in insert and delete query.I have commented the ResultSet part and have not got the error !!

like image 216
Vinish George Avatar asked Mar 06 '26 19:03

Vinish George


1 Answers

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

You should not share Connection, Statement / PreparedStatement or ResultSet objects between multiple threads. Each thread should acquire and release its own resources.

like image 150
Stephen C Avatar answered Mar 08 '26 08:03

Stephen C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!