Wiki
Clone wikineo4j-databridge / 4.3 Importing JDBC databases
4.3 Importing JDBC databases
Databridge can import data from any JDBC-compliant datasource.
Configuring a JDBC import resource descriptor
When configuring an import from a relational database you need to provide connection information and an SQL query string. Here's an example:
#!json { "name": "jdbc-resource", "resource" : "jdbc:mysql://localhost/employees?useSSL=false", "user" : "root", "password" : "", "query" : "SELECT * from departments" }
For more complex queries, you can save your query in a text file with ".sql" extension and reference it from the resource descriptor:
#!json { "resource" : "jdbc:mysql://localhost/employees?useSSL=false", "user" : "root", "password" : "", "query" : "departments.sql" }
Authenticating
If you need to provide a username and password to connect to the database, you can add them as separate attributes in the resource descriptor, as shown in the above examples.
Installing JDBC drivers
Databridge does not provide any JDBC drivers. To connect to a specific database, you must copy an appropriate driver into the lib folder of the importer.
Common JDBC connection strings
Here's a table of connection strings and drivers for some of the JDBC databases supported by Databridge. Consult the vendor documentation for additional information.
Database | Sample connection string | Driver |
---|---|---|
MySQL | jdbc:mysql://<host>/<db> | com.mysql.jdbc.Driver |
Postgresql | jdbc:postgresql://<host>/<db> | org.postgresql.Driver |
Microsoft SQL Server | jdbc:sqlserver://<host>:1433;DatabaseName=<db> | com.microsoft.jdbc.sqlserver.SQLServerDriver |
IBM DB2 | jdbc:db2://myhost:5021/mydb | com.ibm.db2.jcc.DB2Driver |
Oracle | jdbc:oracle:thin:@//<host><:port>/<sid> | oracle.jdbc.driver.OracleDriver |
Configuring the schema mapping
One of the design principles of Databridge is that schema mappings are agnostic of the underlying data being loaded. As a result a schema mapping for a JDBC resource is no different from the schema for any other datasource. Here's a typical example, where the column names come from the JDBC results generated by the query:
#!json { "resource" : "departments_resource.json", "nodes" : [ { "type" : "departments", "identity" : [ "dept_no" ], "update_strategy" : "unique", "labels" : [ { "name" : "departments" } ], "properties" : [ { "name" : "dept_no", "column" : "dept_no" }, { "name" : "dept_name", "column" : "dept_name" } ] } ], "edges" : [ ... ] }
Updated