Database Reference
In-Depth Information
2. Next, we deine a database map with the connection parameters suitable for
our database:
(defdb {:subprotocol "sqlite"
:subname "data/small-sample.sqlite"
:classname "org.sqlite.JDBC"})
3.
Finally, call load-table-data with db and a table name as a symbol or string:
user=> (load-table-data db 'people)
| :relation | :surname | :given_name |
|-------------+----------+-------------|
| father | Addams | Gomez |
| mother | Addams | Morticia |
| brother | Addams | Pugsley |||
How it works…
The load-table-data function passes the database connection information directly
through to clojure.java.jdbc/query.query . It creates an SQL query that returns all
of the ields in the table that is passed in. Each row of the result is a sequence of hashes
mapping column names to data values. This sequence is wrapped in a dataset by
incanter.core/to-dataset .
See also
Connecting to different database systems using JDBC isn't necessarily a dificult task,
but it's dependent on which database you wish to connect to. Oracle has a tutorial for
how to work with JDBC at http://docs.oracle.com/javase/tutorial/jdbc/
basics , and the documentation for the clojure.java.jdbc library has some good
information too ( http://clojure.github.com/java.jdbc/ ) . If you're trying to ind
out what the connection string looks like for a database system, there are lists available
online. The list at http://www.java2s.com/Tutorial/Java/0340__Database/
AListofJDBCDriversconnectionstringdrivername.htm includes the major drivers.
 
Search WWH ::




Custom Search