Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Warning

This module will be removed from the Delft-FEWS code in the 2022.02 release

Introduction

To be able to query timeseries directly using SQL statements Delft-Fews can be set up to act as a jdbc server. This can be done using an OC configuration (which will log in and automatically synchronise date with the MC, thereby assuring all data is constantly being updated), or by running this stand-alone. In the latter case the system will only export what is in the local datastore at startup.

Note that the JDBC server is planned to become obsolete and to be replaced by the webservices like the PI service. Therefore no new features will be developed to the JDBC server.

Fews JDBC Interface

The JDBC Interface provides a virtual access to (virtual) FEWS tables. The JDBC server allows a client application to query the available tables. However not all SQL query statements are supported. Also the type of SQL statements allowed on a table varies per table. See the section on #SQL queries for more details.

The following information is available through the JDBC Server.

Fews JDBC data model

Locations

The locations table allows the client application to query the available FEWS locations.

Parameters

The parameters table allows the client application to query the available FEWS parameters.

Timeseries

The timeseries table allows the client application to query the available FEWS timeseries. The information shown in the TimeSeries table provided by the JDBC server does not match the information of the FEWS TimeSeries table. The JDBC server provides a view of the data of a queried timeseries.

ExTimeSeries

The extended timeseries table allows the client application to query the available FEWS timeseries. The information shown in the ExTimeSeries table provide by the JDBC server is similar to the information presented in the FEWS TimesSeries table. The JDBC server provides a view of the metha data of a queried timeseries.

...

Note! It is currently not possible to query the ExTimeSeries due to bugs.

TimeSeriesGraphs

The TimeSeriesGraphs table allows the client application to retieve an image of a FEWS timeseries chart for the queried timeseries. The query returns a byte array value containing the content of a BufferedImage.

Filters

The Filters is set up as a view. This is because the Filters does not represent a FEWS table. Instead the Filters view represents the content of the FEWS configuration file 'Filters.xml'.

TimeSeriesStats

The TimeSeriesStats is set up as a view. This is because the TimeSeriesStats does not represent a FEWS table. Instead the TimeSeriesStats view shows the results of a statistical analysis performed on the timeseries returned by the query.

Installing a FEWS JDBC Server

Windows

Step 1: Install an OC

Step 2: Delete the "Log4jConfig.xml" from the "OC" directory. When starting the application a new "Log4jConfig-JdbcServer.xml" file will be generated for logging.

...

Notice that the batch calls the file install_JDBC_Service.bat, that contains a list of the *.jar files in the bin directory. If these filenames have changed or the list has changed, this list should be updated. If not, running the service may not be successful. Also notice that your JAVA_HOME environment variable has been set and refers to your JRE directory. This JRE directory should not contain space characters in the name. If so, make a copy of your JRE to a directory with a name without space and set in the run_installscript.bat the JAVA_HOME variable to this new path.

Linux

Step 1: Install an OC

Step 2: Delete the "Log4jConfig.xml" from the "OC" directory. When starting the application a new "Log4jConfig-JdbcServer.xml" file will be generated for logging.

...

Step 5: Stop the FEWS JDBC service by typing exit in the console window where the JDBC startup script was executed. An other option is to kill the process of the FEWS JDBC service.

Starting JDBC Service from FEWS Explorer

For debugging purpose it is possible to start the JDBC from the stand-alone FEWS Explorer. With the F12 key you get a list of debug options. Select "start embedded vjdbc server". The service will start and can be accessed from a database viewer.

Setting up connection in DbVisualizer

Step 1: Install DbVisualizer on your PC. Make sure it is not installed in a folder with spaces, such as "Program Files". When there is a space in the folder name, it will NOT work correctly. This is a DbVisualizer bug that can not be solved by FEWS.
Step 2: Copy the files "commons-logging-1.1.jar" and "vjdbc.jar" to a folder on your computer. These are the drivers used by DBVisualizer. Also this folder name should not contain any space characters (use the 8.3 format).
Step 3: Add a new JDBC driver to DBVisualiser:

...

  • Give it the Alias "<OC-Name> JDBC"
  • Select the vjdbc driver
  • Enter the database URL: "jdbc:vjdbc:rmi://<host>:2000/VJdbc,FewsDatabase" (under <host>, enter the machine where the fews jdbc application runs. You can get the IP adress by typing ipconfig in the command line of the Server). The number "2000" is the default port number, the correct port number is shown in the FEWS log file on the Server when it is started.

Setting up an ODBC-JDBC bridge

The FEWS JDBC Server has been tested with the Easysoft JDBC-ODBC bridge, this can be purchased. This allows the user to access the JDBC Server from other applications like Microsoft ACCESS that do only support ODBC. To use the JDBC driver with the ODBC-JDBC bridge, do the following:

...

Anchor
SQL queries
SQL queries

JDBC server at client application

It is possible to have every client application (OC) to have also its own JDBC service.
Therefore you need to configure in systemConfigFiles\Explorer.xml a piServicePortRange. If configured, the OC automatically starts the JDBC service at the localhost.

...

The FEWS-JDBC Server can also be started embedded from the FEWS Explorer using F12 key.
In all cases that the service runs from the explorer the timezone settings are same as in the FEWS Explorer! This means that a real FEWS-JDBC Server and an embedded FEWS-JDBC Server started from for instance a FEWS Explorer with Dutch timezone settings, may give different timestamps on (the same) timeserie values with a shift up to 2 hours, depending on DLS conversion.

Example SQL queries

There are a number of SQL queries that can be used to retrieve data from the database. Only (read-only) statements are supported. Statements must be formatted as:

...

(warning) Note ! When creating a query using the clause time BETWEEN '2007-03-17 13:00:00' AND '2007-04-01 13:00:00', then it is good to realise that the start time is used as system time for retrieving the timeseries data. This could be important when retrieving 'external forecasting' data with an 'externalForecastTime' later than the start time.This will result in no data being returned.

Example Locations queries

No Format
SELECT name, y,x from Locations ORDER BY name DESC
SELECT name, y,x from Locations WHERE X > '161000'
SELECT * from Locations where id = '46DP0003' OR id = '46DP0004'
SELECT name from Locations WHERE name <> 'Meerselsche Peel (WAM)'
SELECT id, name, y, x from Locations WHERE id LIKE '254%'
SELECT id, name, y, x from Locations WHERE name LIKE '%STUW%' or name LIKE '%Gemaal%'

Example Filters queries

Return all location and parameter combinations from a specific filter

...

No Format
SELECT DISTINCT id FROM filters WHERE issubfilter = false

Example TimeSeries queries

The Time series can be queried with or without the Filter ID. An example of a query without using the filter ID is:

...

Note on Time Series Queries:

  • All values are in the configured time zone of the JDBC application.
  • All unreliable values will not be returned in the query. The complete time step of unreliable values is missing in the returned recordset.

Example TimeSeriesGraphs queries

The Time series can be extracted from the database as a graph (binary obejct) through the Timeseriesgraphs table. Queries with or without the Filter ID can be used, similar to the time series table. An example of a query with the use of a filter ID is:

...

No Format
SELECT *
FROM TimeSeriesgraphs
WHERE filterId = 'Ott_ruw'
AND parameterId = 'H.diepte'
AND (locationId = '10.H.59'  OR locationId = '15.H.20')
AND time BETWEEN '2008-05-01 00:00:00'  AND '2008-05-01 10:00:00'
AND height = 500 AND width = 750 AND timezone='GMT-1';

Example code

Here follows some example code of how client applications can set up a connection to a JDBC server hosted by a FEWS OC.

Setting up a connection in JAVA

No special jars other than the ones provided by the JRE are required.

Code Block
Connection con = DriverManager.getConnection("jdbc:vjdbc:rmi://localhost:2000/VJdbc,FewsDatabase");

//example get Locations
Statement stmt = con.createStatement();
ResultSet set = stmt.executeQuery("SELECT * from Locations");

while (set.next()) {
    System.out.print("Name:" + set.getString("name"));
    System.out.print(", Id:" + set.getString("Id"));
    System.out.print(", X:" + set.getString("x"));
    System.out.print(", y:" + set.getString("y") + "\n");
}

Miscellaneous

Using a different port number (available 200901)

By default the port number of the JDBC Server is 2000. It is possible to use a different port number when starting the application. In the global.properties a property can be added like this:

...

This will start the JDBC Server on port 2078.

Rolling Barrel

When the FEWS JDBC Server is started, the OC rolling barrel configuration will not be used. Instead the Rolling Barrel will run once a day at 02:00 GMT. After the FEWS Rolling Barrel, the compact Database script (only for MS ACCESS databases) will also be executed automatically.

(Java) JDBC Clients, Timezones and DayLightSaving conversion

FEWS stores timeseries with timestamp in GMT, without DayLightSaving (DLS) conversion.

...

Another noticeable issue:
The FEWS-JDBC Server, started as described above, in a standalone manner, has a (hardcoded) timezonesetting of GMT.
The FEWS-JDBC Server can also be started embedded from the FEWS Explorer using F12 key. In the latter case it runs in the timezone set for the FEWS Explorer!
This means that a standalone FEWS-JDBC Server and an embedded FEWS-JDBC Server started from for instance a FEWS Explorer with Dutch timezone settings, may give different timestamps on (the same) timeserie values with a shift up to 2 hours, depending on DLS conversion.

Known issues

  • java.sql.SQLException: java.net.MalformedURLException: no protocol....
    This is an exception that occurs due to a bug in DBVisualizer. Check whether DBVisualizer OR the vjdbc drivers are located in directories that contain spaces in their path. Move them to a directory path without spaces to solve this issue.