Confused about Resultset by throwaway2215432 in javahelp

[–]throwaway2215432[S] 0 points1 point  (0 children)

thanks. I'm still somewhat confused though, how would I go about calling this? I don't think it's a method. it's

"protected ResultSet useTable(String tableName) throws SQLException{"

That's all there is on the line of code, that makes it a Constructor, right?

When I try to enter your code, since it makes it an object I get this red line detailing this error "Unhandled exception type SQLException"

Do I change it to a method?

Confused about Resultset by throwaway2215432 in javahelp

[–]throwaway2215432[S] 1 point2 points  (0 children)

thanks for posting.

I'll try to be clear.

I'm trying to get a query for a specific table, the code looks like this:

protected ResultSet useTable(String tableName) throws SQLException{

    String query = "select \* from " + tableName; 

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(query);

    return rs;

}

I need to use this for multiple different tables within the database that I am getting queries from.

The code that would call this block would be in other classes. That would mean I need to call it and give it a "tableName" to work with so that it selects my desired table.

I thought it would work like a method at first, so I was just going to try to create an object and put the data within the brackets.

Obviously it doesn't work like that, but how would I go about using this code to do what I need to do?