tpeter,

        This sound like some problems I had.  I was trying to import
the mm stuff but this wasn't correct.  Here's a a module
I finally was able to make work.  Hope it helps.


                Brent

P.S.    Hey, I went to BYU one semester a long time ago..


---------------------- cut here -------------------------
import java.io.*;

import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;


// Table Printer Server


public class TPServ extends HttpServlet {

    /**
     * Creates a new BLPServe (was LinkCheckerServlet)
     */
    public TPServ() {
    }

    /**
     * Services a single request from a client.
     * @param req the HTTP request
     * @param res the HTTP response
     * @exception IOException If an I/O error has occured
     */


  public void doGet (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
  {
    String table = req.getParameter("table");
    ServletOutputStream out = res.getOutputStream();
    String outStr;

    res.setContentType("text/html");

    out.println("<HTML>");
    out.println("<HEAD>");
    out.println("<TITLE>Table Printer Server</TITLE>");
    out.println("</HEAD>");
    out.println("<BODY>");

    out.println("<H3>Class.forName</H3>");

    out.flush();


    try {

        Class.forName("org.gjt.mm.mysql.Driver");

        out.println("<H3>Trying connection...</H3>");

        out.flush();

        Connection Conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        Conn = DriverManager.getConnection(
"jdbc:mysql://localhost/bookstore?user=<user>;password=<passwd>");

        stmt = Conn.createStatement();

//      String[] tables = {"db","user","host"};

        String[] tables = {"person", "item", "rank"};

        int tnum = tables.length;
        if (table != null) {
            tnum = 1;
            tables[0] = table;
        }


        for (int j=0; j < tnum; j++) {
            // Execute an SQL query, and retreive a ResultSet
            rs = stmt.executeQuery("SELECT * FROM "+tables[j]);


            ResultSetMetaData rsmd = rs.getMetaData();


            // Display the result set in a table
            out.println("\n<BR>\n<HR><H3>Table: " + tables[j] + "</H3>\n");
            out.println("<TABLE border=1 bgcolor=cyan>");

            // Title the table with Column Headers
            int numcols = rsmd.getColumnCount();
            out.print("<TR>");
            for (int i=1; i<= numcols; i++)
                out.print("<TH>" + rsmd.getColumnLabel(i));
            out.println("</TR>");

            // Print out result
            while(rs.next()) {
                out.println("<TR>");
                for (int i=1; i<= numcols; i++) {
                    Object obj = rs.getObject(i);
                    out.print("<TD>");
                    out.print((obj != null) ?
                              obj.toString() :
                              "&nbsp;");
                }
                out.println("</TR>");
            }
            out.println("</TABLE>");
        }

        if (stmt != null) stmt.close();
        if (Conn != null) Conn.close();

        //    catch (SQLException ignored) { }
    }
    catch (Exception E) {
        out.println("Connection failed : " + E.getMessage());
 }

    out.println("<HR><H3>completed connection call</H3>");


    out.println("</BODY>");

    out.flush();

  }

}




----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to