I have a servlet that recieves user entered parameters from an html form and inserts them into a user table in MYSQL, or at least is supposed to. I can get it to update the table with specific values but not with the user variables. I know the single quote marks are for inserting specific values but without them it doesn't properly work.
The parameters are parsed correctly into the variables, so I just can't figure out how to ge tthe variables into the database. Any help would be wonderful
register.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Register</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<CENTER><IMG SRC="dvdti.jpg" ALIGN=middle > </CENTER>
<HR>
<H1 ALIGN="CENTER">Please enter your registration details:</H1>
<FORM ACTION="http://localhost:8080/examples/servlet/Assignment1.register">
<BR>First Name: <input type="text" NAME="Ufirst_name"><BR>
<BR>Last Name: <input TYPE="TEXT" NAME="Ulast_name"><BR>
<BR>Address: <INPUT TYPE="text" name="Uaddress"><BR>
<BR>E-mail: <INPUT TYPE="TEXT" NAME="Uemail"><BR
<BR>Password: <INPUT TYPE="password" NAME="Upassword"><BR>
<CENTER>
<INPUT TYPE="SUBMIT" VALUE="Register">
</CENTER>
</FORM>
</BODY>
</HTML>
register.java:
package Assignment1;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
// Connects to a database to retrieve music data
public class register extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Database connection code starts here
Connection conn = null;
// loading jdbc driver for mysql (help in mysql.jar file in classpath)
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch(Exception e) {
System.out.println(e);
}
// connecting to database
try{
// connection string for demos database, username demos, password demo-pass
conn = DriverManager.getConnection
("jdbc:mysql://mudfoot.doc.stu.mmu.ac.uk:3306/roddiea?user=roddiea&password=");
System.out.println("Connection to database successful.");
}
catch(SQLException se) {
System.out.println(se);
}
// Create select statement and execute it
try { Statement stmt2 = conn.createStatement();
// Get the regdetails from the reg form
String Ufirst_name = request.getParameter("Ufirst_name");
String Ulast_name = request.getParameter("Ulast_name");
String Uaddress = request.getParameter("Uaddress");
String Uemail = request.getParameter("Uemail");
String Upassword = request.getParameter("Upassword");
stmt2.executeUpdate("INSERT INTO customer(first_name, last_name, address, email, password)" + "VALUES('Ufirst_name', 'Ulast_name', 'Uaddress', 'Uemail', 'Upassword')");
System.out.println (stmt2);
out.println(stmt2);
out.println(Ufirst_name + Ulast_name + Uaddress + Uemail + Upassword);
// close the html
out.println("</BODY></HTML>");
stmt2.close();
conn.close();
}catch(SQLException se) {
System.out.println(se);
}
}
}
Message was edited by:
Altered_Carbon
Message was edited by:
Altered_Carbon
I also realise that this is a more MYSQL titled problem, but those forums look rubbish <_<