I have a method :
public void dbQuery(String query, String what) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(what.equals("temp_table")) {
String temporary_table = rs.getString("table_name_temp");
System.out.println(temporary_table);
return;
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
}
}
String query = "EXEC temptables.dbo.create_temp_cdr 'SIP'";
String temporary_table = db.dbQuery(query,"temp_table");
How do I get the return of a void to use it in another db.dbQuery() ?
PS : I need a value from dbQuery() so I can construct another query to call dbQuery() again
You can either have your method not be void, and have a return type, then you can have the line
which would return the temporary_table variable.
Another way would be to pass by reference to the method. For example, you can pass a StringBuilder object to the method. Any changes to this object in the method will then also apply after the method has returned.
A call to this method of
would have the output of: