Question

I seem to be having some issues with my result sets I have named them differently but they both seem to have the same data in but I can't figure it out why.

String query = "SELECT * FROM blog_comments;";
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int colNum = rsmd.getColumnCount();
boolean more = rs.next();

String query2 = "SELECT * FROM blog_entries;";
ResultSet rs2 = stmt.executeQuery(query2);
ResultSetMetaData rsmd2 = rs2.getMetaData();
int colNum2 = rsmd2.getColumnCount();
boolean more2 = rs2.next();

I have looked in debugging and they both have the same columns but i don't think they should have any suggestions.

Was it helpful?

Solution

you need a new Statement to instantiate your new ResultSet.

Statement st1 = Conn.CreateStatement();
Statement st2 = Conn.CreateStatement();

ResultSet rs1 = st1.executeQuery();
ResultSet rs2 = st2.executeQuery();

From Statement API.

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top