2 messages in com.mysql.lists.javaServlet problem
FromSent OnAttachments
Nikolaus J. Sucher02 Nov 1999 23:34 
Mark Matthews03 Nov 1999 05:19 
Subject:Servlet problem
From:Nikolaus J. Sucher (suc@ust.hk)
Date:11/02/1999 11:34:20 PM
List:com.mysql.lists.java

Hi ,

I have MySQL 3.25, Apache 1.3.9, ApacheJServ 1.1. I wrote the following servlet. The problem is that nothing gets inserted into the database. What is wrong. Similar code works well as an applet!

import java.io.*; import java.sql.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;

public class FormProcServlet extends HttpServlet implements SingleThreadModel{

private String url = new String("jdbc:mysql://myhost.somewhere.edo:3306/http_auth?user=me&password=passwd");

private String message = "Initializing"; PrintWriter out = null;

public String getServletInfo() { return "Registration form processing servlet"; }

public void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

String firstName = req.getParameter("first_name"); String lastName = req.getParameter("last_name"); String eMail = req.getParameter("e_mail"); String Address = req.getParameter("address"); String userName = req.getParameter("user_name"); String Password = req.getParameter("passwd");

// Set the Output Stream to HTML resp.setContentType("text/html");

// Get a PrintWriter output object PrintWriter out = resp.getWriter();

// send html back to the browser out.println("<html>"); out.println("<head><title>First Servlet</title></head>"); out.println("<body>"); out.println("<center><h1>TCMExchange Registration</h1></center>"); out.println("Thank you for registering at TCMExchange!"); out.println("<p>"); out.println("You entered the following information:"); out.println("<p>"); out.println("First Name: "); out.println(firstName); out.println("<p>"); out.println("Last Name: "); out.println(lastName); out.println("<p>"); out.println("E-mail: "); out.println(eMail); out.println("<p>"); out.println("Address: "); out.println(Address); out.println("<p>"); out.println("Username: "); out.println(userName); out.println("<p>"); out.println("Password: "); out.println(Password); out.println("</body></html>"); }

//Add the data from the form to the MySQL database private void updateDatabase() {

//Load the driver try { Class.forName("org.gjt.mm.mysql.Driver").newInstance();

//Make a connection to the database Connection conn = DriverManager.getConnection(url);

//Create a statement for the data and database metadata Statement state = conn.createStatement();

//Update the database (this is just a test INSERT statement)

state.executeUpdate("INSERT INTO mysql_auth SET passwd='test'");

//Clean up state.close(); conn.close();

} catch (Exception exce) { //do something } } }