How to setup a mysql data source for Persevere

Persevere logo

If you don’t know Persevere yet, check out its impressive list of features (JSONPath/JSON-RPC/Comet support, etc…).

Here is a short tutorial to expose your MySQL tables through the persevere JSON REST interface.

  1. Download persevere and unzip it.

  2. Download the JDBC driver for MySQL and put the jar file into the “persevere/lib” folder.

  3. Create a new file in “persevere/WEB-INF/config” named “myDatabase.json”

  4. We will now configure the data source: (replace “myDatabase” and “myTable” by your database and table names.) ({ "id":"myDatabase.json", "sources": [ { "name":"myTable", "sourceClass":"org.persvr.datasource.DatabaseTableDataSource", "driver":"com.mysql.jdbc.Driver", "connection": "jdbc:mysql://localhost/myDatabase?user=myDbUser&pass=", "table":"myTable", "idColumn":"id", "dataColumns": [ "lastname", "firstname", ...and so on with your table columns ], "schema":{ "data":{"$ref":"../``myTable``/"} } } ] }Don’t forget to change your database user name and password !

  5. run persevere (“java -jar start.jar”) and visit the following pages:

What to do next ?

  • Add other tables: “sources” is an array !
  • Use UTF8: Adds the following at the end of the connection string: &useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8
  • Add methods to the class or to its prototype (take a look at WEB-INF/config/examples.json)
  • Write a script to auto-generate the config file from a database structure (and post it on the persevere forum)
  • Read the Persevere Javascript Client Documentation and start coding applications !
    Have fun !

Tags : ,
Categories : Software, Javascript

Comments

comments powered by Disqus
Copyright © 2000-2022 - Eric Abouaf