I keep getting this whenever I try to use this method.
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.cre
While iterating through your ResultSet
, you are reusing the Statement
object for updating the data (inside your query
method), which closes the ResultSet
from the query.
See the ResultSet documentation:
"A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results."
You should create separate Statements for the query and the update, and pass them to your query method:
public ResultSet query(String s, Statement statement) throws SQLException {
...
}
I assume that statement
is declared static
inside your class - there is usually no need for that: create the two statements for query and update in the constructor of your class, and either pass them to the query()
method or use the one or the other depending on the statement.