GeoTools : DB2DataStore

The DataStore interface is general to all of the implemented DataStores. The following document describes the use of a DB2DataStore and is based on the How to use a PostGISDataStore.

These docs have moved to the user guide:

Creating a DB2DataStore

The following code shows how to use the DataStoreFinder to create a DB2DataStore.

import java.util.HashMap;
import java.util.Map;



Map params = new HashMap();
params.put("dbtype", "db2");        //must be db2 or DB2
params.put("host", "localhost");        //the name or ip address of the machine running DB2
params.put("port", "50000");  //the port that DB2 is running on (generally 50000)
params.put("database", "geotools");      //the name of the database to connect to.
params.put("user", "db2admin");         //the user to connect with
params.put("passwd", "adminpw");               //the password of the user
params.put("tabschema", "SPEAR");               //the table schema

DataStore datastore = DataStoreFinder.getDataStore(params);
if (datastore == null) {
	throw new Exception("create datastore failed");
FeatureSource fsStreams = datastore.getFeatureSource("STREAMS");

System.out.println("Streams count: " + fsStreams.getCount(Query.ALL));

Once the DB2DataStore is created, you can use it like any other DataStore.

Attachments: (application/x-zip-compressed) (application/zip)