1

In java, when executing a query like :

statement stm = stm.executeQuery("select * from table1");

How can I view the results of this query on the command prompt ?

Thanks for any help

1 Answer 1

4
ResultSet rs = stmt.executeQuery("select * from table1");

int columns = rs.getMetaData().getColumnCount();

StringBuilder message = new StringBuilder();

while (rs.next()) {
    for (int i = 1; i <= columns; i++) {
        message.append(rs.getString(i) + " ");
    }
    message.append("\n");
}

System.out.println(message);  // print table contents
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.