The source code of MySQLServlet.java : /* Java servlet to access CS MySQL database directly This connects as the dummy user CSC9YD with password ec201112A to the database sbj and can access any tables granted access to CSC9YD. Needs MySQL Connector/J driver in the classpath (e.g. WEB-INF/lib/). Simon Jones */ import java.io.IOException; import java.io.PrintWriter; import java.sql.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MySQLServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC " + "\"-//W3C//DTD HTML 4.01 " + "Transitional//EN\">"); out.println("<html><body><pre>"); String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://shark.cs.stir.ac.uk/sbj"; // The last part is the name of the database Connection con; ResultSet rs; Statement stmt; try { Class.forName(driver); } catch (java.lang.ClassNotFoundException e) { out.print("ClassNotFoundException: "); out.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "CSC9YD", "ec201112A"); // This a public dummy user stmt = con.createStatement(); rs = stmt.executeQuery("SELECT DISTINCT Season, Title FROM sbj.Panto"); // Note the sbj. ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); int rowCount = 0; while (rs.next()) { out.println("Row " + (++rowCount) + ": "); for (int i = 1; i <= numberOfColumns; i++) { out.print(" Column " + i + ": "); out.print(rsmd.getColumnLabel(i) + ": "); // or could use columnName out.println(rs.getString(i)); } } con.close(); } catch (SQLException ex) { out.println("SQLException: " + ex.getMessage()); } out.println("</pre></body></html>"); } }