StelsEngine Example

This simple example demonstrates basic principles of the StelsEngine use (you can find other samples in the StelsEngine package that you can download from our website). In the same way StelsEngine can be used for storing and fast processing large arrays of data in your Java applications.

Suppose you have a simple data array of employees in a table-like format, i.e., in rows and columns:

Name

Hire_date

Salary

Bill Adams

21-05-1992

32000

Mary Jones

12-06-1995

37500

Sue Smith

03-04-1992

45000

Dan Roberts

20-10-1999

50000

 

And you need to deal with the following tasks: sort the list by date, perform a search by name and find the maximum salary. With StelsEngine, you can do it all easily:

 

// create a JDBC connection

Connection conn = DriverManager.getConnection("jdbc:jstels:engine");

// create a Statement object to execute the queries

Statement stmt = conn.createStatement();

// create a data table

stmt.execute("CREATE TABLE employee(name STRING, hiredate DATETIME, salary INTEGER)");

 

// insert the records into the table

stmt.execute("INSERT INTO employee(name, hiredate, salary) VALUES('Bill Adams',to_date('21-05-1992','dd-MM-yyyy'), 32000)");

stmt.execute("INSERT INTO employee(name, hiredate, salary) VALUES('Mary Jones',to_date('12-06-1995','dd-MM-yyyy'), 37500)");

stmt.execute("INSERT INTO employee(name, hiredate, salary) VALUES('Sue Smith',to_date('03-04-1992','dd-MM-yyyy'), 45000)");

stmt.execute("INSERT INTO employee(name, hiredate, salary) VALUES('Dan Roberts',to_date('20-10-1999','dd-MM-yyyy'), 50000)");

 

// get a list of employees sorted by hire date

ResultSet rs = stmt.executeQuery("SELECT * FROM employee ORDER BY hiredate");

// ... process the result set

 

// search by name

ResultSet rs2 = stmt.executeQuery("SELECT * FROM employee WHERE name LIKE ‘mary%’");

// ... process the result set

 

// find the maximum salary

ResultSet rs3 = stmt.executeQuery("SELECT MAX(salary) FROM employee");

// ... process the result set

 

As it follows from the example mentioned above, StelsEngine uses classical JDBC API for processing table-oriented data. Connection class as a matter represents a database that stores data tables in operating memory. Using Statement class, you can easily execute SQL queries to these tables. As a result of the query, the Statement object returns a ResultSet instance that can be used for further processing in your application (e.g. to display it in a JTable).