3

I want to create a JDBC DataStore with these parameters:

Map<String,Object> params = new HashMap();
params.put("dbtype","postgis");
params.put("host","localhost");
params.put("port",5432);
params.put("schema","public");
params.put("database","mydb");
params.put("user","postgres");
params.put("passwd","postgres");

DataStore store = DataStoreFinder.getDataStore(params);
System.out.println(store);// prints null

Iterator it = DataStoreFinder.getAvailableDataStores();
while(it.hasNext()){
  System.out.println(it.next());
}

the output:

null
org.geotools.data.shapefile.ShapefileDirectorFactory@5e316c74
org.geotools.data.shapefile.ShapefileDataStoreFactory@7ee955a8

my libraries (pom.xml):

<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-main</artifactId>
  <version>19-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-jdbc</artifactId>
  <version>19-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-data</artifactId>
  <version>19-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-shapefile</artifactId>
  <version>19-SNAPSHOT</version>
</dependency>

Why does it create a null datastore?

4

It correctly returns null because you have not made a DataStore available that can handle the parameters you have passed in.

As you can see from the list of available datastores you can only create Shapefile datastores, since that is the only implementation that the program can find on the classpath.

If you want to use a PostGIS datastore you will need to include the PostGIS plugin jars by adding the following dependency to your pom file.

<dependency>
   <groupId>org.geotools.jdbc</groupId>
   <artifactId>gt-jdbc-postgis</artifactId>
   <version>${geotools.version}</version>
 </dependency>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.