0
public execute_query(String Query)
{
    Resultset rs = smt.executeQuery();
    return (rs); //something like this
}

I have an execute_query function in separate java file wherein I have returned resultset reference variable. Now how to use this rs in another java file?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Don't do this. Transform the result and return the result of the transformation. Result sets have their lifetime bound to the statement and connection, and returning them to something without control over the statement and connection is bound to give you a lot of bugs related to the object lifetime. Your API as shown also just (badly) wraps the statement API, that does not add any value. – Mark Rotteveel Feb 10 '18 at 08:59

1 Answers1

0

First you need to tell the function to return a ResultSet by doing

public ResultSet execute_query

and then in the other file you do

private queryClass object = new QueryClass(); ResultSet newResultSet = object.executeQuery(query);

Zuenonentu
  • 302
  • 1
  • 3
  • 16