Home Answers Viewqa JSP-Servlet Inserting values in servlet and jsp

 
 


kushal BANSAL
Inserting values in servlet and jsp
1 Answer(s)      5 years and 3 months ago
Posted in : JSP-Servlet

How to Insert the values into database table using Servlet and JSP?

View Answers

February 25, 2008 at 6:34 PM


//Insert the values into database table using Servlet and JSP.

//Code Example
DataInsertionExam.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DataInsertionExam extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url = &quot;jdbc:<a href="mysql://localhost:3306/&quot" target="_blank">mysql://localhost:3306/&quot</a>;
String db = &quot;register&quot;
Connection conn;
   try{
   Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
     conn = DriverManager.getConnection(url+db,&quot;root&quot;,&quot;root&quot;);
     Statement statement = conn.createStatement();
     String query = &quot;insert into userdata values(1,'Amardeep', 'Programmer')&quot;;
     int i = statement.executeUpdate(query);

    if(i!=0){

    out.println(&quot;The record has been inserted&quot;);
      }
      else{
      out.println(&quot;Sorry! Failure&quot;);
      }
      statement.close();
      }
      catch (Exception e){
      System.out.println(e);
      }
      }
      }

     web.xml

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
    &lt;!--&lt;!DOCTYPE web-app
    PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;

    &quot;<a href="http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt" target="_blank">http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt</a>; --&gt;
    &lt;web-app&gt;
     &lt;servlet&gt;
    &lt;servlet-name&gt;DataInsert&lt;/servlet-name&gt;
    &lt;servlet-class&gt;DataInsertionExam&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
 &lt;servlet-name&gt;DataInsert&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/DataInsertionExam&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;
&lt;/web-app&gt;









Related Pages:
inserting value - JSP-Servlet
the jsp inserting the value in the jsp after that i want these value inserted the database mySQl with the help of servlet. Inserting form data   Inserting form data into database using JSP and ServletGiven code will illustrate you
Inserting Image(s) - JSP-Servlet
Inserting Image(s)  Hello, I need sample code using java servlet...;); PreparedStatement pst = con.prepareStatement("insert into uploadfile values(?,?,?)"); File file = new File("C:/apache-tomcat-5.5.23/webapps/jsp/red_rose2.gif
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
passing values - JSP-Servlet
passing values  hi this is my jsp page...=null; /*Inserting Name,Hallno:,Time,Date,Mobileno: details using method..._DataInsertion(Name,Hallno,Time,Date,Mobileno,Status) values('"+name+"','"+hallno+"','"+time
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html... to insert all selected values in data base correspondent to each like if user
Inserting Image(s) - JSP-Servlet
Inserting Image(s)  Hello Guys, Thank you so much for your support so far. I appreciate everything you guys have done for me. Please what I wanted was java servlet or jsp codes that I can use to insert and retrieve image from MS
inserting all the values in a html table column
inserting all the values in a html table column  strong text hai everyone, i'm a fresher to servlet i need to know that, how can i insert all the values in a html table column into a database. Thanks in advance
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting to a databse by a servlet.I used the example in "Inserting Data In Database table
retrive values - JSP-Servlet
retrive values  how to get multiple values from html to jsp
inserting picture in ms access
inserting picture in ms access  hi i am sanatan, how to insert picture in ms access by jsp.   <%@page import="java.sql.*,java.io.*"%>... into user(name,address,image) values(?,?,?)"); pre.setString(1
retrive values - JSP-Servlet
retrive values  how to retrive multiple values from html to jsp  Hi Friend, Try the following code: 1)calljsp.html: Enter Name: Enter Address: Gender:MF Qualification: Btech MBA MCA MSC
insert values - JSP-Servlet
insert values  How to insert values in the oracle database using JSP. Plz tell the core answer as soon as possible .  HiThis is html...;insert user_details values('"+username+"','"+jobposition+"
previous values in servlet - JSP-Servlet
previous values in servlet  Hi... I've an application where there are two links link1 and link2 when i clicked link1 there's a form with relevant... to the link1 after link2 the same values are still in the form... How to remove
Facing Problem to insert Multiple Array values in database - JSP-Servlet
Facing Problem to insert Multiple Array values in database  Hai friend , Iam beginner in jsp and creating the project in shopping cart but ihave facing the problem while inserting the data in database. iam using the MsAccess
Loading updated values - JSP-Servlet
Loading updated values  In my jsp project profile updating is one of that part. While updating i have to show updated values in choice list for birthday date column. How can we show the previously updated values in choice list
How to get a values - JSP-Servlet
How to get a values  Dear sir, I have one input text field and one submit button .Within one file how to get a values within a same jsp. Thanks and Regards Harini Veerapur.  Hi Friend, Try the following
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
how to set the values in jsp
how to set the values in jsp  how to set the values text boxs in jsp frm dbase via servlet
How to get a values - JSP-Servlet
When i submit a form ,inother jsp i.e newMESWithUpload.jsp in that jsp if i do strSubject=request.getParameter("subject... getting a null value aprt from a attachmented file,so how to get a other values
servlet - JSP-Servlet
Inserting values in servlet and jsp  How to Insert the values into database table using Servlet and JSP?  Insert the values into database table using Servlet and JSP.Code ExampleDataInsertionExam.javaimport java.io.
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem is as follows: i am creating a feedback form of a college. this feedback form will ask some question and students have to answer those question with the help
How to pass multiple values from a servlet to JSP?
How to pass multiple values from a servlet to JSP?  hi, I want to pass multiple values form a servlet to JSP. Hw do i do that? I am able to send one...) values
How to carry multiple values from a Servlet to a JSP?
How to carry multiple values from a Servlet to a JSP?  By using the below code I am able to carry the username to a JSP (single value... needs to be carried from my servlet to a JSP. How do I do
Get values from JSP pages - JSP-Servlet
Get values from JSP pages  I have welcome.jsp in which it has... to another JSP page?Do you want to use database to add column values or you want... Name, City, State) into into next jsp page. note these are not Text fields
count values using jsp - JSP-Servlet
count values using jsp  hai deepak i have a query i am dynamically generating textbox with names in that i am having headings... many subheading like that is it posssible with jsp i think it is possible
getting values from database - JSP-Servlet
JSP code separately.If it will not display database values then try your code in Servlet. Thanks...getting values from database  I tried the following code abc.html
dynamic multiplecheckbox values insertion - JSP-Servlet
dynamic multiplecheckbox values insertion  hi How to insert dynamically generated checkbox values to store in mysql data base using jsp?  Hi Friend, Try the following code: 1)checkbox.jsp: Name
passing the form values with image upload - JSP-Servlet
passing the form values with image upload  Hii . I want to get the solution for passing values with an image uploading form. I cant access the request values from the fields rather than image . I want to know how can cut
how to get the image path when inserting the image into pdf file in jsp - JSP-Servlet
how to get the image path when inserting the image into pdf file in jsp  Hi Friend, my image path;C:/images/photo.jpg. i am getting the below error error: The type Image is ambiguous document.open(); Image
how to get a values from processRecord - JSP-Servlet
how to get a values from processRecord  dear sir, i have a problem in getting a values from java to jsp.Here jsp is used to read a excel sheet that intern call a java program so i want a column values i.e a column contains
how to store a dynamic values - JSP-Servlet
in that i have stored a values from a excel sheet specified column values and i... and bonus is ~5 . Thanks Hr in another arraylist i have a values ~2,~3,~4,~5 values.Now i want to insert these values into a string ,use that string
how to get the image path when inserting the image into pdf file in jsp - JSP-Servlet
how to get the image path when inserting the image into pdf file in jsp  I am using the below code but i am getting the error at .getInstance. i am using the itext.jar now.Plz help to me <% Document document=new
reain values
reain values  Sir I have Jsp page for regisering customers,when i submit form it goes to servlet in servelets it checks for the username if it already exits i m using reuest.sendredirect to same jsp but all textbox values
values of Combo boxes are not stored in database - JSP-Servlet
values of Combo boxes are not stored in database   i have some combo box values. when i click the submit button after select combo box values, the values are not going in database. please review the code: function
getting error while inserting values in database
getting error while inserting values in database  AddUser.java... into LTCINFO.PERSONS values ('"+LASTNAME+"','"+FIRSTNAME+"','"+ADDRESS+"','"+CITY... followin error i don't know why "ORA-00947: not enough values". kindly chk
How to Sort Column values of a jsp table - JSP-Servlet
How to Sort Column values of a jsp table  Hi Friend Please help me. I am displaying reultset values on multiple jsp page. I want to sort selected column values on every page onclick of an event its very urgent pleasehelp
inserting into mysql database with uid to be primary key and autoincrement
; Here is the code of inserting values from jsp form to database...inserting into mysql database with uid to be primary key and autoincrement  hello, i am new to jsp and facing problem in creating a database entry
Problem in inserting clob data in jsp
Problem in inserting clob data in jsp  how to insert any rich text editor data (which have more than 32766 characters) in a clob type column of oracle database with jsp
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp..  i am trying to make a virtual classroom website in jsp using netbeans.i...,gender,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname
retrieving values from dynamically added textboxes in jsp - JSP-Servlet
retrieving values from dynamically added textboxes in jsp  hai friends, iam new to this site ,please help me in this senario in jsp how to retrieve values from dynamically added textbox like we can see in naukri.com
Transferring values between javascript and java code in jsp - JSP-Servlet
Transferring values between javascript and java code in jsp  Is there a way to transfer values between the javascripts and the java code(scriptlet, expressions etc) in a jsp page?   Hi Friend, 1)Pass value from jsp
Passing java variables from JSP to Servlet - return null values
from JSP to servlet gives null values. I got msg=null. Is there another way...Passing java variables from JSP to Servlet - return null values  I want to pass some variables from a JSP page to a servlet. These variables are from
not able to get values from jsp file - JSP-Servlet
not able to get values from jsp file  hi thanks for u feedback, her am sending the file jsp and servlet but in the servlet file am not able to get... and reply me its urgent.. jsp file ========= Display file upload form
insert image - JSP-Servlet
into oracle database using JSP but i am not geting so please friends send me the code for inserting image into database using JSP   Hi Friend, Try... = connection.prepareStatement("insert into save_image(name, image) values
Displaying Constant values from Interface in JSP - JSP-Servlet
Displaying Constant values from Interface in JSP  Hi, ******Sorry... need to display suitable fields in my jsp but this should be done upon suitable... values public interface ProjConstant { public static final String PROJECT_NAME
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList...",total); when I code this like in my jsp <%ArrayList<Integer> data= new ArrayList(); %> Its not printing the values. do i need to do any
Jsp-Servlet
Jsp-Servlet  how can i display the values in jsp pages as list from servlet ? can you help me out plz ? thanks
Web Related - JSP-Servlet
. How can i update my webpage by inserting the value in database. The webpage... time and all these values i want to show on my web page dynamically.plz help me... as the JSP pages which will help you in solving your problem. In these JSP pages
Relative listboxes in JSP - JSP-Servlet
inserting to tabler: 1) Is the redeem gift box having some new values... Part A -------- I want to have two relative listboxes within a JSP... from transactional table) 2) There should be a submit that inserts values from

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.