How do I get a subset of a result set

I am getting a result set from a remote data source. After the resultset is returned how can I do a select on the result to return a subset of records?

My code:

package com.drawingpdmw1;

import java.sql.*;

import com.ibm.as400.access.*;

/**

* @author sde

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

publicclass getLastDashNumberConnection{

public String errorString;

public String literalerrorString;

public String maxRecSeq;

public getLastDashNumberConnection(String arg0){

AS400JDBCDataSource datasource =new AS400JDBCDataSource("gvas400");

datasource.setTranslateBinary(true);

datasource.setUser("drawchg");

datasource.setPassword("webabc1");

try{

Connection connection = datasource.getConnection();

Statement stmt = connection.createStatement();

String sql ="select distinct dmdrawno from webprddt6.drawmext3 Where dmdrawno LIKE '%" + arg0.substring(0,6) +"%'";

ResultSet rs = stmt.executeQuery(sql);

while(rs.next()){

System.out.println(rs.getString("dmdrawno").trim());

}

errorString ="";

literalerrorString ="NoError";

}

catch(SQLException sqle){

System.out.println("Error");

System.out.println(sqle);

errorString ="Warning!!! A New Dash Number could not be created!";

literalerrorString ="Error";

}

}

}

[2580 byte] By [SLDykea] at [2007-11-27 10:43:30]
# 1

1. Can you write an SQL statement that returns the records you are interested in, in the first place?

2. You forgot to close your result set, statement and connection!

3. Although you are writing to System.out, I assume eventually your

method will return a list of business objects. Your code can filter on

whatever criteria you like to decide whether or not to add a row's data to this list.

BigDaddyLoveHandlesa at 2007-7-28 20:00:46 > top of Java-index,Java Essentials,New To Java...
# 2

First, thanks for the info on closing my objects.

Now as far as the data here is my situation. The purpose of this class is to return the next dash number that can be used for a series of partnumbers. In most cases the series is constructed with only one type of dash numbers. Example: -401, -403, -405 dashes that start with a 4 are assemblies. This is easy to figure out the nex dash(-407).

However, some of our partnumber series have dashes like -001, -003, -005 which are detail level part numbers along with the -401 etc.

Now a user needs to create a new dash number. First, is this a detail dash or an assy dash. My idea is to get all the possibilites for a series, check for dash types, then return the next dash for each type.

SLDykea at 2007-7-28 20:00:46 > top of Java-index,Java Essentials,New To Java...
# 3

Also, its advisable to blank out the url, userID, and password of your database before posting your example on the forum. Now quick! go change that password! Too late, I'm buying a condo in Florida with your credit card.

George123a at 2007-7-28 20:00:46 > top of Java-index,Java Essentials,New To Java...
# 4

Trust me, you want get very far with the disclosed info.

Thanks for reminding me about this though, I just forgot what I normally do.

SLDykea at 2007-7-28 20:00:46 > top of Java-index,Java Essentials,New To Java...