/* ' Copyright by Erica Andrews aka CyLiKoN JeZuZ aka Li'L CJ, ' December 1999. No one is permitted to implement this servlet ' or any portion of it on their site without the express written consent ' of the author (cylikon@hotmail.com - ./IcedPinky/). ' All rights reserved. ' This servlet was hand-coded in by Erica on Dec. 27,1999 ' It simply lists (as links) all the sites in one table of my database. ' The servlet uses the ' gweMySQLJDBC 0.9.2 driver (rather than the JDBC-ODBC bridge) ' and MySQL 3.22.9 for database connectivity. */ import java.io.*; import java.util.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import gwe.sql.*; public class SqlServletListAll extends HttpServlet { // -- status of our database connection -true or false (but NOT used in this // -- particular servlet) boolean dbConnected; public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { //Get the response's PrintWriter to return text to the client. PrintWriter toClient = res.getWriter(); try { // --- set up the driver and connect to the database ----- Class.forName ("gwe.sql.gweMysqlDriver"); Connection conn = DriverManager.getConnection ("jdbc:mysql://:3306/siteindex2","guest","guest"); // -- get ready to execute a query - create a statement ------ Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("SELECT * FROM thesites"); // ----- fetch and print out the results -------- // first, set the "content type" header of the response res.setContentType("text/html"); while (rset.next ()) { String id=rset.getString(1).trim(); String itsgroup=rset.getString(2).trim(); String title=rset.getString(3).trim(); String url=rset.getString(4).trim(); toClient.print (""); toClient.print (title); toClient.print(""); toClient.print("
"); } // -- handling miscellaneous problems with the query --------- } catch(SQLException e) { e.printStackTrace(); toClient.println( "A problem occured while processing your query. " + "Please try again."); } // -------- Handling "driver not found" problems ----- catch (ClassNotFoundException e) { System.err.println("JDBC-ODBC driver not found"); throw new UnavailableException (this, "Database driver not found"); } // ----------------- // Close the writer; the response is done. toClient.close(); } }