2

I had written a service for querying data from SQL.

public class DummyDeviceTokenService {
    Connection connect = null;
    Statement statement = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;

    public DummyDeviceTokenService() throws Exception{
        Class.forName("com.mysql.jdbc.Driver");

        connect = DriverManager
                .getConnection("jdbc:mysql://localhost/student?"
                        + "user=root&password=root");

        statement = connect.createStatement();
    }

    public ResultSet selectAll(int offset,int range)throws Exception{
        resultSet = statement
                .executeQuery("select * from employee where id > " + offset + " AND id < "+range);
        return resultSet;
    }
}

I want to return a stream from public ResultSet selectAll(int offset,int range).

I went through java.util.stream with ResultSet - Stack Overflow but these were little complex methods.

Please suggest some good way to do this.

Community
  • 1
  • 1
avy
  • 417
  • 1
  • 9
  • 21
  • 3
    Holger already suggested the good way to do this. Look no further unless you prefer simplicity over correctness. – Marko Topolnik Sep 12 '16 at 06:41
  • 1
    The only alternative is to wait for a 3rd party library or future Java version providing you exactly that functionality in an easy-to-use method. – Holger Sep 12 '16 at 09:59
  • I answered the question below. take a look if it's what you're looking for. – user_3380739 Dec 04 '16 at 01:20

0 Answers0