Minto
Minto

Reputation: 47

SQL query display onto window

I'm trying to output the sql query results onto a window of sorts when the button is clicked but when clicked it displays "org.hsqlb.jdbc.JDBCResultSet@75fbe2c7", dont know if it's relative the number at the end changes my database connection works

JButton btnReview = new JButton("Review Seller Requests");
btnReview.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        try {
            String query = "SELECT email FROM seller_requests";
            PreparedStatement pSt = connect.prepareStatement(query);
            rS = pSt.executeQuery();

            if(rS.next()) {
                JOptionPane.showMessageDialog(null, rS);
            }

            pSt.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

Can JOptionPane be used or is there another way?

Upvotes: 1

Views: 124

Answers (2)

swifty
swifty

Reputation: 181

Or you can also get the column value by using the column names of the table.

rS.getString("COLUMN_NAME");

so in your case it should be.

JOptionPane.showMessageDialog(null, rS.getString("COLUMN_NAME")); // for example

Upvotes: 1

M A
M A

Reputation: 72844

To view the results, you need to get the appropriate column value from the ResultSet object after calling its next method. You can use ResultSet#getString(int columnIndex) to do this:

if(rS.next()) {
    String email = rS.getString(1);  // column index starts at 1, not zero.
    // display email
}

Upvotes: 1

Related Questions