Here you can find the source of resultSetToSet(PreparedStatement statement)
public static Set<String> resultSetToSet(PreparedStatement statement) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashSet; import java.util.Set; public class Main { public static Set<String> resultSetToSet(PreparedStatement statement) throws SQLException { ResultSet results = statement.executeQuery(); try {/*from w w w . ja v a 2 s. co m*/ Set<String> strings = new HashSet<String>(); while (results.next()) { strings.add(results.getString(1)); } return strings; } finally { statement.close(); } } }