Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

inserting data into database using a jsp

843836Mar 23 2005 — edited Mar 31 2005
Hello all
I am trying to insert data into a mysql table using a jsp. I have a simple page called newuser.jsp (shown below), which collects data from the user. It calls the page validate_new_user.jsp also shown below. Now it complies fine, when I enter data into the form and hit submit I am taken to the success.htm page. But when I go into my database and use the command �select * from user_details� the data I entered in from the newuser.jsp page is not there. I am using tomcat 5.5. Please help as this is really wrecking my head, it may be something simple that I have left out. Thanks in advance.

Here is the code for newuser.jsp
<html>
<head>
<title>new user</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">



<h1>Please enter your details</h1>


<form action="validate_new_user.jsp" method="post">
	<table cellspacing="5" cellpadding="5" border="1">
		<tr>
			<td align="right">Name:</td>
			<td><input type="text" name="NewName"></td>
		</tr>
		<tr>
			<td align="right">Email Address:</td>
			<td><input type="text" name="EmailAddress"></td>
		</tr>
		<tr>
			<td align="right">Nationality:</td>
			<td><input type="text" name="Nationality"></td>
		</tr>
		<tr>
			<td align="right">User Name:</td>
			<td><input type="text" name="UserName"></td>
		</tr>
		<tr>
			<td align="right">Password:</td>
			<td><input type="password" name="Password"></td>
		</tr>
		
	</table>
	<input type="submit" value="Submit">
</form>
	

</body>
</html>
Here is the code for validate_new_user.jsp
<html>
<head>
<title>Validate New User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.sql.*" %>

<%
		Connection con = null;
		
		String names = request.getParameter("NewName");
		String eaddress = request.getParameter("EmailAddress");
		String nation = request.getParameter("Nationality");
		String userid = request.getParameter("UserName");
		String pw = request.getParameter("Password");
		
		
		String queryText = "insert into user_details (\"fullName\", \"emailAddress\", \"nationality\", \"username\", \"password\") 
values('"+names+"','"+eaddress+"','"+nation+"','"+userid+"','"+pw+"')";

		try {
  			Class.forName("com.mysql.jdbc.Driver").newInstance();
  			con = 

DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","password");
  			
			Statement stat = con.createStatement();
  			
			ResultSet rst = stat.executeQuery(queryText);
			
			rst.close();
			stat.close();
			con.close();
		} catch (Exception e) { }

		response.sendRedirect("success.htm");
%>



</body>
</html>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2005
Added on Mar 23 2005
11 comments
2,071 views