wiki:WebApplication

JDBC (Java Databse Connectivity)

How do I connect databases from Java?

Use JDBC http://java.sun.com/javase/technologies/database/ API. There are several implementations of JDBC drivers for PostgreSQL, MySQL, Microsoft SQLServer, Microsoft Access, Oracle, DB2, etc.

Find a database specific JDBC driver from the web, and add it to your CLASSPATH. If your are developing web applications, the JDBC driver must be placed in WEB-INF/lib folder. Several sample codes are presented in the above tutorial.

How do I use SQLite databases from Java?

To the best of my knowledge, the simplest way is to use SQLite JDBC driver, which works in reasonable speed. Although there are several other implementations of SQLite JDBC drivers, to properly compile and set up these drivers is a little bit bothersome.

How do I retrieve web contents in Java web applications?

Within a Servlet, use getServletContect().getResource() method. http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResource(java.lang.String)

Homework

Create a database of your own, for example, by reading a tab-separated data file or by retrieving web contents. You may use XML, JSON, or any format you like. Then, create two Servlet programs; both of them retrieves database contents, and one of the Servlets generates a graphic image of this data, and the other sends the data to a GWT client program (interface) in JSON format for producing HTML table data (using FlexTable?, etc. in GWT).

  • Examples
    • Drawing stock chart images from your data, and displaying detailed table data as HTML (GWT interface).
    • Drawing gene tracks, and displaying detailed annotations of genes.