import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class SunServlet5 extends HttpServlet { // The database connection Connection con; //The statement Statement stmt; //The queryString String queryString = null; public void init (ServletConfig conf) throws ServletException { super.init(conf); } /* * doPost() mehtod to handle user interaction */ public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // ----confugure this for the site String username = "nobody"; String password = null; // the URL that will connect to TECFA's MySQL server // Syntax: jdbc:TYPE:machine:port/DB_NAME // String url = "jdbc:mysql://localhost:3306/staf2x String url = "jdbc:mysql://tecfa2.unige.ch:3306/staf2x"; //----configure END try { Class.forName ("org.gjt.mm.mysql.Driver"); //Establish Connection to the database at URL with username and password con = DriverManager.getConnection(url, username, password); System.out.println("Ok, the connection to the database is working."); } catch (Exception e) // (ClassNotFoudException and SQLException) { throw (new UnavailableException(this, "Sorry! The database didn't load!")); } try { String title = "Student Grades Page"; out.println ("
"); out.println("Here is the complete student grades information:"); out.println("
"+el+" | "); } out.println("
---|
" + el + " | "); } out.println("
Now please click 'Back' on the toolbar to go back to the grades mangetment page and do whatever you want to the students' grades."); }catch (SQLException ex) { out.println("
"); while (ex !=null){ out.println("Message: " + ex.getMessage()); out.println("SQLState: " + ex.getSQLState()); out.println("ErrorCode: " + ex.getErrorCode()); ex = ex.getNextException(); out.println(""); } out.println (""); } out.println("
SUN June 2000 "); out.println("Source Code"); out.println(""); try { con.close();} catch(Exception e) {} return; } }