This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Using custom SQL statements

Documents for the development of and with JVx.

--Using custom SQL statements

Postby Development@SIB » Thu Dec 03, 2015 5:06 pm

This article is outdated - please use our new system at

JVx has very useful database support based on DBStorage and DBAccess. The DBStorage is very powerful and supports automatic foreign, primary and unique key detection. It reads allowed (check constraints) and default values automatically from your database table.

But sometimes the recommended usage is not enough for your requirements. We recommend to use following:

Syntax: [ Download ] [ Hide ]
DBStorage contacts = new DBStorage();

This code is enough to have full CRUD support and automatic linked cell editor detection.

But it's also possible to read from a view and write-back into a table:

Syntax: [ Download ] [ Hide ]
DBStorage players = new DBStorage();

If you want to add additional columns, it's better using a view. But if you use a view, the automatic link cell editor detection won't work because of missing metadata information.

But it's trivial to add missing metadata information:

Syntax: [ Download ] [ Hide ]
     new String[] {"EXT_PLAYER_ID", "EXT_PLAYER_NAME"},
     new String[] {"ID", "NAME"});

The statement will add a link cell editor for the columns EXT_PLAYER_ID and EXT_PLAYER_NAME (from the view). The link cell editor will read data from EXTINFO (table, view, ...) and will use ID and NAME column as display and selection values (JVx hides ID columns per default).

If you have a prepared storage for your link cell editor records, it's also possible to use following:

Syntax: [ Download ] [ Hide ]
public DBStorage getExtInfo()
    DBStorage extInfo = new DBStorage();
    extInfo.setRestrictCondition(new Equals("TYPE", "U18"));
    //not relevant for this storage

    return extInfo;


     new String[] {"EXT_PLAYER_ID", "EXT_PLAYER_NAME"},
     new String[] {"ID", "NAME"});

Above usage was still very trivial and DBStorage supports very custom statements like this:
Syntax: [ Download ] [ Hide ]
DBStorage users = new DBStorage();
users.setQueryColumns(new String[] {"u.user_id", "u.user_name",
                                    "c.company_id", "c.company_name",
                                    "d.department_id", "d.department_name"});
users.setFromClause("users u, companies c, departments d");
users.setWhereClause("u.dep_id = and d.comp_id =");
users.setDefaultSort(new SortDefinition("company_name", "department_name", "user_name"));;

or this style:

Syntax: [ Download ] [ Hide ]
DBStorage users = new DBStorage();
users.setFromClause("(u.user_id, u.user_name, c.company_id, c.company_name, d.department_id, " +
                        "d.department_name "+
                     "from users u, companies c, departments d " +
                     "where u.dep_id = and d.comp_id = " +
                     "order by company_name, department_name, user_name) users");;

The last syntax is nice for copy/paste a statement from your DB tool. The DBStorage executes:

Code: Select all
select * from <fromclause>
User avatar
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation