Menu

Querying Java 2 dimensional Arrays - The ArraySQL class

The ArraySQL was added to the FormattedDataSet API.
ArraySQL allows SQL like synax to be applied to Arrays.
This class can be used with the FormattedDataSet or as a standalone utility class.
The API also has the ability to convert ResultSet's into 2 dimensional Arrays.
This allows you to query ResultSets as the following example shows.
See the javadocs at http://www.fdsapi.com for more examples.

// The following examples shows how ArraySQL can be used to add a row number to a ResultSet
DataAccess da=... See javadocs for an example
ResultSetConverter rsc=da.getResultSetConverter("select * from employees");
String[] header=rsc.getMetaData();
Object[][] data=rsc.getResultSet();
ArraySQL asql=new ArraySQL(header, "select rowNum(), * from array");
data=asql.execute(data);

// Although the example only uses Strings, other data types are supported
header={"fname","lname"};
data={{"steve","souza"},{"steve","smith"},{"jeff","beck"},{"sam","souza"},};
ArraySQL asql=new ArraySQL(header, "select rowNum(), date(), col0, fname, lname, * from array where lname in ('souza', 'beck') && fname!='sam' order by lname desc, col0");
data=asql.execute(data); // returns 2 rows and orders the results

// The same object can be used on data multiple times
data=asql.execute(data2);

Posted by Steve Souza 2004-09-26

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.