Using Database Functions

There are times when we just want to display data similar to a report or list, and in doing so, we also want to make use of database functions to perform some sort of arithmetic or maybe just to concatenate strings as in this example.

JED allows us to make use of Field objects to present a Function to the underlying database system. The Field class has a special Type which we can invoke upon its initial creation through its constructor. When we declare such a Field, it would look like this:

Field field1 = new Field("","name",Field.Type.FUNCTION);

Note that in this instance we don't need to declare a table name, just a column name. "name" doesn't refer to any field in the database table, but is used on output in the JSON string for the client side to process. See the tab labelled Java below to see how we retrieve our data.

This particular example uses a join to match up Landline phone numbers with employees, while concatenating the first and last name of the employee. Basically, we want a SELECT statement that looks like this:

			SELECT CONCAT(employees.first_name," ",employees.last_name),landlines.number
                FROM employees LEFT JOIN landlines ON ORDER BY employees.last_name asc
The end result is a presorted list of employees with their corresponding phone numbers.

Live example

Name Landline Phone
Loading data from server
Name Landline Phone