Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add external links

...

An artificial example demonstrating a few techniques that are now possible thanks to the above:

  • You can use zxJDBC, a pythonic (DB API 2.0) interface allowing the use of databases accessible via JDBC. The driver (postgresql-*.jar or ojdbc6.jar) used here is available in classpath because we copied it from /dspace/lib/.
  • You can use Java libraries, demonstrated here by java.util.Properties used to read dspace.cfg.
  • Here we read the database driver, connection string, user and password from dspace.cfg and then pass it to zxJDBC to create a connection.
  • We could use DB API 2.0 methods like cursor.fetchall() to get query results. Here I chose to use the Python zip() function to return the query results in a custom format.
  • You can use a context manager (Python "with" keyword) around a zxJDBC cursor to manage the scope of the DB transaction.
  • You can't use the Python "with" keyword around the java.util.Properties as it is a Java class which doesn't implement a Python context manager.
  • DB connection here is open in init() and closed in destroy() only to demonstrate the servlet's constructor and destructor. You should not keep a DB connection open for the whole time the servlet is loaded.

...