473,416 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to store information in the JSP form in the database SQL server 2005?

Hey guys i have created a JSP page including one JSP form(which i have created with the help of HTML tags).

Now i am facing the problem..as to how to store the information provided by the user...in the SQL server 2005..which is acting as a database in my project.

So plz help me regarding this.

Thanx.

For ue reference..i am providing u with the coding of my project.


Expand|Select|Wrap|Line Numbers
  1. index.jsp:-
  2. <%-- 
  3.     Document   : index
  4.     Created on : Aug 28, 2010, 8:04:10 AM
  5.     Author     : Prateek
  6. --%>
  7.  
  8. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  10.    "http://www.w3.org/TR/html4/loose.dtd">
  11.  
  12. <html>
  13.     <head>
  14.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  15.         <title> Login Form </title>
  16.     </head>
  17.     <body
  18.     <form action="success.html" method="get"/>
  19.  
  20.         <br>
  21.         <br>
  22.    <center><h3> Please fill in the following information in order to continue with your registration</h3></center>
  23.    <br>
  24.    <br>
  25.    <table border="2" bordercolor="black"  align="center"  cellpadding="5" cellspacing="2" width="450" height="300">
  26.         <tr>
  27.             <td ><center><font color="black"><b>First Name </b></font></center></td>
  28.             <td><center><input type="text" name="name"></center></td>
  29.         </tr>
  30.  
  31.         <tr>
  32.            <td><center><font color="black"><b>Last Name</b></font></center></td>
  33.            <td><center><input type="text" name="name"></center></td>
  34.         </tr>
  35.  
  36.         <tr>
  37.            <td><center><font color="black"><b>Address</b></font></center></td>
  38.            <td><center><input type="text" name="address"></center></td>
  39.         </tr>
  40.  
  41.         <tr>
  42.            <td><center><font color="black"><b>Contact Number</b></font></center></td>
  43.            <td><center><input type="text" name="cno"></center></td>
  44.         </tr>
  45.  
  46.         <tr>
  47.            <td><center><font color="black"><b>E-Mail ID</b></font></center></td>
  48.            <td><center><input type="text" name="E-Mail"></center></td>
  49.         </tr>
  50.  
  51.         <tr>
  52.            <td><center><font color="black"><b>Registration Date</b></font></center></td>
  53.            <td><center><input type="text" name="Rd"/></center></td>
  54.         </tr>
  55.  
  56.  
  57.     </table>
  58. </body>
  59. <br>
  60. <br>
  61. <center><input type="submit" value="     Save       ">&nbsp;&nbsp;&nbsp;<input type="reset" value="     Reset        " onclick="location.reload()"></center>
  62. </html>
  63.  
  64. Login.servlet:-
  65. /*
  66.  * To change this template, choose Tools | Templates
  67.  * and open the template in the editor.
  68.  */
  69.  
  70.  
  71. import java.io.IOException;
  72. import java.io.PrintWriter;
  73. import java.sql.Connection;
  74. import java.sql.DriverManager;
  75. import java.sql.PreparedStatement;
  76. import java.sql.SQLException;
  77. import javax.servlet.ServletException;
  78. import javax.servlet.http.HttpServlet;
  79. import javax.servlet.http.HttpServletRequest;
  80. import javax.servlet.http.HttpServletResponse;
  81. import javax.sql.*;
  82.  
  83. public class Login extends HttpServlet 
  84. {
  85.  
  86.  
  87.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  88.     throws ServletException, IOException, ClassNotFoundException, SQLException 
  89.     {
  90.  
  91.         response.setContentType("text/html;charset=UTF-8");
  92.         PrintWriter out = response.getWriter();
  93.  
  94.          String fn =request.getParameter("First Name");
  95.          String ln =request.getParameter("Last Name");
  96.          String address=request.getParameter("Address");
  97.          String cno=request.getParameter("cno");
  98.          String EMail=request.getParameter("E-Maild ID");
  99.          String Rd=request.getParameter("Registration Date");
  100.  
  101.         try 
  102.         {
  103.              if(fn.length()==0 && ln.length()==0 && address.length()==0 && cno.length()==0 && EMail.length()==0 && Rd.length()==0)
  104.                 {
  105.                     response.sendRedirect("error.html");
  106.                 }
  107.              else
  108.                 {
  109.                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  110.                 Connection c = DriverManager.getConnection("jdbc:odbc:Family","","");
  111.                 PreparedStatement ps = c.prepareStatement("insert into Friends (FirstName,LastName,Address,ContactNo,EMailID,RegistrationDate) values(?,?,?,?,?,?)");
  112.                 ps.setString(1, fn);
  113.                 ps.setString(2, ln);
  114.                 ps.setString(3, address);
  115.                 ps.setString(4, cno);
  116.                 ps.setString(5, EMail);
  117.                 ps.setString(6, Rd);
  118.  
  119.                 ps.executeUpdate();
  120.              response.sendRedirect("success.html");
  121.                 }
  122.  
  123.         } 
  124.  
  125.         catch(Exception ec)
  126.         {
  127.             out.print(ec);
  128.         }
  129.  
  130.         finally 
  131.         {
  132.             out.close();
  133.         }
  134.     } 
  135.  
  136.         // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  137.     /** 
  138.     * Handles the HTTP <code>GET</code> method.
  139.     * @param request servlet request
  140.     * @param response servlet response
  141.     */
  142.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  143.     throws ServletException, IOException, SQLException {
  144.         processRequest(request, response);
  145.     } 
  146.  
  147.     /** 
  148.     * Handles the HTTP <code>POST</code> method.
  149.     * @param request servlet request
  150.     * @param response servlet response
  151.     */
  152.     @Override
  153.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  154.     throws ServletException, IOException {
  155.         processRequest(request, response);
  156.     }
  157.  
  158.     /** 
  159.     * Returns a short description of the servlet.
  160.     */
  161.     @Override
  162.     public String getServletInfo() {
  163.         return "Short description";
  164.     }
  165.     // </editor-fold>
  166.  
  167. }
  168.  
  169.  
  170.  
  171.  
Sep 25 '10 #1
0 1707

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Darryl Kerkeslager | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/sseoverview.asp SQL Server Express was developed with two distinct uses in mind. The first is as a server product,...
5
by: HSP | last post by:
hi. i need to restore an old database. The db was backed up using a DLT drive, using 2 volumes. The content for the tapes was copied to file onto Solaris machine using rsh and dd (for backup...
4
by: Greg P | last post by:
I know this is a long post, please bear with me. I have been working on this all weekend to no avail although I have done a good amount of research (see most pertinent links that I've looked at...
7
by: Greg P | last post by:
I know this is a long post, please bear with me. I have been working on this all weekend to no avail although I have done a good amount of research (see most pertinent links that I've looked at...
2
by: d.grabov | last post by:
We are trying to use source control to store our database objects and queries in Perforce. The general idea is to produce scripts which create all objects in the DB and then store the SQL in source...
3
by: Lee T. Hawkins | last post by:
I am having a number of problems over the last two full days trying to get an ASP.NET 2.0 application to connect to a SQL Server 2005 database... First off, I built this application w/ Visual...
0
Coldfire
by: Coldfire | last post by:
Since i cannot show the differences in a two-column like table. I am first putting MS SQL Server 2005 and then MySQL 5.x. MS SQL Server 2005 Brief Overview - SQL Server is a full-fledged...
1
by: Andy B | last post by:
I am making a web application that would randomly create an activation code and put it in a database. The web application would then send it in an email to the user with a link to go to and enter...
5
by: Andy B | last post by:
I am making a web application that would randomly create an activation code and put it in a database. The web application would then send it in an email to the user with a link to go to and enter...
2
by: mfaisalwarraich | last post by:
hi everybody, im new in vb.net. im trying to make a win form application using visual studio 2008 express edition (which is free to download and install). i have installed a ms sql server 2005...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.