Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 19th, 2006, 05:01 PM
hatim hatim is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 hatim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 54 sec
Reputation Power: 0
Servlet and JDBC

[nobr]Hi,
I am new in servlet and i need help, in my code there is no error when compiling, but i can't store data into my customer table . Can you help.
Here is the HTML for the register page. When the customer hits the register button the Servlet/JSP should check to see if the customer already exists in the customer table of the database. Since two customers of a bank may have the same name you must check the name and address not just the name. The information on the register page should be store in mysql table customers which has got the field bellow: create table customers (name text, customerid text, address text, email text, password text, type int);.
a. Add the customer details to the customers table (you will need to generate a unique customer id for the customer and add that too).
[/code]
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="http://www3.unl.ac.uk:8186/username/servlet/cw?action=registerme">
<H1> CheapBank User Registration for </H1>

Enter your name: <INPUT TYPE=TEXT NAME="name"> <BR>
Enter your address: <INPUT TYPE=TEXT NAME="address"> <BR>
Enter your email: <INPUT TYPE=TEXT NAME="email"> <BR>
Enter your password: <INPUT TYPE=TEXT NAME="password"> <BR>


Enter a description for your new account: <INPUT TYPE=TEXT NAME="description"> <BR>


<INPUT TYPE="SUBMIT" VALUE="Register">
</FORM>
</BODY>
</HTML>
[/code]





import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.awt.*;
public class register extends HttpServlet
{
Connection connection;
String name, customerid, address, email, password, type;
private Connection con = null;
public Statement s = null;
private ResultSet rs = null;
public String URL = "org.gjt.mm.mysql.Driver";
public void init(ServletConfig config)
throws ServletException
{
try {
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://www3.unl.ac.uk:3306/username","username","userid");
}

catch (Exception e) {
e.printStackTrace();
con = null;
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
response.setContentType("text/html");

try // try to add data to the database
{
Statement statement = connection.createStatement();
int r=statement.executeUpdate("insert into customers values('"+name+"','"+customerid+"','"+address+"', '"+email+"', '"+password+"', '"+type+"')");
}
catch (Exception e)
{
out.println("sorry an error occured "+e);
e.printStackTrace();
}

try // print out all the messages
{
Statement statement = connection.createStatement();
ResultSet rs=statement.executeQuery("select * from customers;");
while (rs.next())
{
out.println(rs.getString("name")+": "+rs.getString("customerid")+":"+rs.getString("address")+":"+rs.getString("email")+": "+rs.getString("password")+": "+rs.getString("type"));
out.println("<br>");
}
}
catch (Exception e)
{
out.println(e);
}


response.sendRedirect("http://www3.unl.ac.uk:8186/username/login.html");

out.println("<HTML>");
out.println("<BODY>");
out.println("<FORM METHOD=\"POST\" ");
out.println("ACTION=\"http://www3.unl.ac.uk:8186/username/servlet/register?action=register\">");
out.println("<H1> CheapBank User Registration Form <BR>");
out.println("Enter your name: <INPUT TYPE=TEXT NAME=\"name\"> <BR>");
out.println("Enter your address: <INPUT TYPE=TEXT NAME=\"address\"> <BR>");
out.println("Enter your email: <INPUT TYPE=TEXT NAME=\"email\"> <BR>");
out.println("Enter your password: <INPUT TYPE=TEXT NAME=\"password\"> <BR>");
out.println("Enter your description for your account: <INPUT TYPE=TEXT NAME=\"description\"> <BR>");
out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Register\">");
out.println("</FORM>");
out.println("</BODY>");
out.println("</HTML>");
}
}

[/nobr]

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Servlet and JDBC


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT