H2 Plugin¶
Supports direct access to a H2 database.
H2 is the second generation of HSQL, a popular embedded Java database. The current database is not a true spatial database as it does not have any form of spatial indexing.
Maven
Note that the groupId
is org.geotools.jdbc
for this and other JDBC plugin modules.
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-h2</artifactId>
<version>${geotools.version}</version>
</dependency>
Connection Parameters¶
Parameter |
Description |
---|---|
|
Must be the string |
|
The database to connect to |
|
User name |
Creating¶
Here is a quick example:
Map<String, Object> params = new HashMap<>();
params.put("dbtype", "h2");
params.put("database", "geotools");
DataStore datastore = DataStoreFinder.getDataStore(params);
The above will reference a database file named geotools
located in the current working directory.
A full path may also be specified:
Map<String, Object> params = new HashMap<>();
params.put("dbtype", "h2");
params.put("database", "/abs/path/to/geotools");
DataStore datastore = DataStoreFinder.getDataStore(params);
The above examples create a connection to H2 in embedded mode. One limitation to this approach is that it only allows for a single Java process to access the database at any one time. H2 also offers a server mode in which access to the underlying database is made via traditional client-server TCP connection, and removes the embedded single process restriction:
Map<String, Object> params = new HashMap<>();
params.put("dbtype", "h2");
params.put("host", "localhost");
params.put("port", 9902);
params.put("database", "geotools");
params.put("passwd", "geotools");
params.put("passwd", "geotools");
DataStore datastore = DataStoreFinder.getDataStore(params);