Get an item from each Row

Asked

Viewed 27 times

0

How can I get an Item from each Row?

For example, I have a column with the following rows:

  • TEST
  • TEST
  • TESTE2
  • TESTE2
  • TESTE3

As I wished:

  • TEST
  • TESTE2
  • TESTE3

My code:

public void carregar(){
        qy = "SELECT TESTEROWS FROM COLUNA";
        try {
            PreparedStatement ps = MySQL.getConn().prepareStatement(qy);
            ResultSet rs = ps.executeQuery();
            if (rs.next()){
                setItem(TypeItem.valueOf(rs.getString("Type")));
            }
            loadItemsLoja();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

With while it is only returning all (obvious), with if it only returns me the first. How can I get one from each Row?

2 answers

1


0

There are two ways to do this:

SELECT distinct TESTEROWS FROM COLUNA

or

SELECT TESTEROWS FROM COLUNA group by TESTEROWS

Browser other questions tagged

You are not signed in. Login or sign up in order to post.