a utility for generating JSON from SQL queries using JDBC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. jdbcjson
  2. ========
  3. JDBCJSON is a simple utility for generating JSON from SQL queries
  4. using JDBC. JDBCJSON takes a simple properties file for it's
  5. configuration.
  6. basic usage
  7. -----------
  8. First, create your properties file. JDBCJSON breaks properties down
  9. by jobs. Each job has four parameters: `driver`, `url`, `sql`, and `out`.
  10. `driver` is an optional parameter for specifying the driver class to be
  11. registered. `driver` is only required for non-JDBC4 drivers. JDBC4 drivers
  12. should self register. `url` is the JDBC connection URL (see your driver
  13. documentation for more details.) `sql` is the SQL statement executed
  14. whose result is used to generate the JSON. `out` is the path for
  15. resulting JSON. Take the following example:
  16. people.driver = net.sourceforge.jtds.jdbc.Driver
  17. people.url = jdbc:jtds:sqlserver://myserver/db;user=sa;password=sa
  18. people.sql = SELECT * FROM people
  19. people.out = people.json
  20. This properties file will create a job called _people_ that will query
  21. a SQL Server database on localhost, selecting all the columns from
  22. _people_, and output the result to _people.json_. Multiple jobs may be
  23. specified in a single properties file.
  24. Next, run JDBCJSON. It's always a good idea to specify the debug switch
  25. the first time you run a new properties file against JDBC. The debug
  26. switch will give you additional warnings about things like unsupported
  27. fields (BLOBs, for example.)
  28. java -jar jdbcjson.jar -d people.properties
  29. advanced usage
  30. --------------
  31. Only the url parameter of a properties file is required. The `url` and `out`
  32. properties have default values, based on the job name. The `sql` parameter
  33. defaults to `SELECT * FROM <jobname>`. The `out` parameter defaults to
  34. `<jobname>.json`. Thus:
  35. mytable.url = jdbc:postgresql://localhost/mydb?user=postgres&password=postgres
  36. Is the same as:
  37. mytable.url = jdbc:postgresql://localhost/mydb?user=postgres&password=postgres
  38. mytable.sql = SELECT * FROM mytable
  39. mytable.out = mytable.json