Database Reference
In-Depth Information
How to do it…
Now, all you need to do is call incanter.excel/read-xls :
user=> (read-xls "data/small-sample-header.xls")
| given-name | surname | relation |
|------------+---------+-------------|
| Gomez | Addams | father |
| Morticia | Addams | mother |
| Pugsley | Addams | brother |
How it works…
This can read standard Excel iles (.xls) and the XML-based ile format introduced in
Excel 2003 (.xlsx).
Reading data from JDBC databases
Reading data from a relational database is only slightly more complicated than reading from
Excel, and much of the extra complication involves connecting to the database.
Fortunately, there's a Clojure-contributed package that sits on top of JDBC (the Java database
connector API, http://www.oracle.com/technetwork/java/javase/jdbc/index.
html ) and makes working with databases much easier. In this example, we'll load a table
from an SQLite database ( http://www.sqlite.org/ ), which stores the database in a
single ile.
Getting ready
First, list the dependencies in your Leiningen project.clj ile. We will also need to include
the database driver library. For this example, it is org.xerial/sqlite-jdbc :
(defproject getting-data "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]
[org.clojure/java.jdbc "0.3.3"]
[org.xerial/sqlite-jdbc "3.7.15-M1"]])
Then, load the modules into your REPL or script ile:
(require '[incanter.core :as i]
'[clojure.java.jdbc :as j])
 
Search WWH ::




Custom Search