Skip to content

Executing SQL Instructions

Antoine Gourlay edited this page Jul 23, 2012 · 2 revisions

It is very easy to execute an SQL instruction on a Gdms source. See the Gdms SQL Reference for the description of the supported grammar.

Getting the result of a query

DataSourceFactory dsf = new DataSourceFactory();

// register a source
dsf.getSourceManager().register("myTable", new File("/home/toto/myFile.shp"));

// get a datasource from a query
DataSource ds = dsf.getDataSourceFromSQL(
    "SELECT * FROM myTable WHERE myField = 'value';");

By default the resulting source is read-only, as any other DataSource.

Executing a query with no result

If a query does not return anything or has a result we are not interested in, it is even easier:

DataSourceFactory dsf = new DataSourceFactory();

// register a source
dsf.getSourceManager().register("myTable", new File("/home/toto/myFile.shp"));

// execute a query
dsf.executeSQL("INSERT INTO myTable (myField) VALUES ('value2') ");

External links:

Clone this wiki locally