Hacking J-Bird (Version 0.5.2): Import from relational databases

It is possible to import the master list or species checklists from any relational database for which you have a Java JDBC driver. To do so, you will provide information that is necessary for Java to connect to the database and an SQL query that returns the names of the species to be imported. You will store the connection information and query in a file and then select the file when importing data into J-Bird. J-Bird will connect to the database, run the query, and then present the results to you just as it does when importing from a file of comma-separated values or from an Excel spreadsheet.

Connection information and query

Format of parameter file

Parameters are stored in a plain text file according to the following formatting.

Example parameter file:

Name of parameter file

The name of the property file must begin with "JDBC-import" and end with ".jpf". This is a convention that J-Bird uses to identify parameter files that will be used to import from relational database. An example of a name might be: JDBC-import-Oklahoma.jpf. If when you attempt to import data, J-Bird appears to be trying to import the contents of your configuration file rather than data extracted from the database, the cause is probably that the name of the configuration file has not been recognized as that of a configuration file.

Importing

To import the master species list from a database, construct the configuration file; run the master list builder and select the option for building the master list from table types that include relational database.

To import a checklist from a database, follow the first steps that you would for any import. When asked to select a file that contains the data (or a web page), select the parameter file. J-Bird will detect the name and import from the relational database.

Example: Context for both examples

In the examples below, the goal is import a checklist from a relational database of checklists. The database is named BirdLists, and it contains three tables.

In the examples, names of species on one of the checklists will be imported. To keep the examples simple, checklist names will be ignored, and species names will be imported from checklist number 4. An SQL query for extracting species from checklist 4 is:


	SELECT Species.CommonName FROM Species, ListMembers
		WHERE ListMembers.ListNo = 4
			AND ListMembers.SpecNo = Species.SpecNo

Example: Importing from Microsoft Access

To import data from Access databases an extra step is required: the database must be available as an ODBC Data Source Name (DSN). This is discussed first because the Data Source Name that you give the database will be used in the configuration parameters that are used by J-Bird. If you have not already set up an ODBC Data Source Name, follow the steps below.

The Access database in this example is named BirdLists, and for simplicity the ODBC DSN has also been named BirdLists. The parameters are as follows.

The exact text of the configuration file follows.


	DriverClassname = sun.jdbc.odbc.JdbcOdbcDriver
	DatabaseURL = jdbc:odbc:BirdLists
	SQLQuery = SELECT Species.CommonName \
			FROM Species, ListMembers \
			WHERE ListMembers.ListNo = 4 \
				AND ListMembers.SpecNo = Species.SpecNo

Note that the use of backslashes permits the query to be nicely formatted by spreading it out over several lines.

The configuration is complete.

Importing from MySQL

In this example, the database BirdLists resides in a MySQL database that is running on the same computer that is running J-Bird. A location of the driver must be specified along with a database username and password.

The exact text of the configuration file follows.


	ClassPath = /usr/share/jdbc-mysql/lib/mysql-connector-java-3.0.11-stable-bin.jar
	DriverClassname = com.mysql.jdbc.Driver
	DatabaseURL = jdbc:mysql:///BirdLists
	DatabaseUser = Twitcher
	DatabasePassword = tiktiktik
	SQLQuery = SELECT Species.CommonName \
			FROM Species, ListMembers \
			WHERE ListMembers.ListNo = 4 \
				AND ListMembers.SpecNo = Species.SpecNo

The configuration is complete.


Previous (Hacking J-Bird - main page) Contents Next (Hacking - arbitrary access)

SourceForge Logo

Page last updated 21 May 2005