storing details in database on clicking submit button

storing details in database on clicking submit button

I am using JSP in NetBeans and have developed an application form which has fileds naming 'Name' and 'ID'.I want to store the details of these two fields in the MYSQL database on clicking submit button. I am unable to do this.Can u tell me how to code this page and where and should be my code written?

This is my simple code...Tell me where an what code should I write to store the values in data base table?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
Name:<input type="text" name="name" value="" size="10" /><br><br>
ID:<input type="text" name="id" value="" size="10" /><br><br>
<input type="submit" value="Submit" name="submit" />
</body>
</html>
View Answers

April 6, 2010 at 4:14 PM

Hi Friend,

Try the following code:

<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<form method="post">
<table>
<tr><td>ID:</td><td><input type="text" name="id" value="" size="10" /></td></tr>
<tr><td>Name:</td><td><input type="text" name="name" value="" size="10" /></td></tr>
<tr><td><input type="submit" value="Submit" name="submit" /></td></tr>
</table>
</form>
</html>
<%
String id=request.getParameter("id");
String name=request.getParameter("name");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
Statement st=connection.createStatement();
int i=st.executeUpdate("insert into data(id,name) values('"+id+"','"+name+"')");
out.println("inserted successfully");
}
catch(Exception e){}
%>

Thanks









Related Tutorials/Questions & Answers:
storing details in database on clicking submit button - JSP-Servlet
storing details in database on clicking submit button  I am using JSP... 'Name' and 'ID'.I want to store the details of these two fields in the MYSQL database on clicking submit button. I am unable to do this.Can u tell me how to code
Submit button to MySQL database?
Submit button to MySQL database?  Need help linking html code to mysql database <html> <head> <meta http-equiv="Content-Type...="text" name="Level" /> </form> <td><input type="submit
Advertisements
Submit button to MySQL database?
Submit button to MySQL database?  Need help linking html code to mysql database <html> <head> <meta http-equiv="Content-Type...="text" name="Level" /> </form> <td><input type="submit
How to save form fields into the MySql Database without submit button in jsp?
How to save form fields into the MySql Database without submit button in jsp?  I want to store user inputs into the database using javasccript or ajax or jqury but without submit button. Form Contains three fields
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using submit  Hi, I created a button when i click on button new textbox... will click submit button the text should be submitted(it shows the value in text
submit button
submit button  <p>hi I am trying to insert record in database using hibernate in JSP(Netbeans). When I click insert button it should go...; <input type="submit" value="Insert" name="login" /> <
Submit comments in database when user clicks on submit button
Submit comments in database when user clicks on submit button... database when user clicks the submit button of the page. Create a database: First... be integer number then click submit button. If all the values are submitted
storing csv into oracle database
storing csv into oracle database  i want jsp code for storing csv file into oracle database
autogeneration of a random number and displaying it as a alert message to the user on clicking submit
on the submit button as a "alert message" and this refrence number act as primary key... is generated it should be inserted into database along with the details of addform when... to the user on clicking submit  Hi, In my project order purchase system under
JSP Submit Button
JSP Submit Button  Sir, I have a JSP page with 2 Submit button, both calls doPost method of same servlet. If I click any submit button the text box value get refreshed and set to null or blank, that should not happen. Plz help
Uploading a Software and storing in the database
Uploading a Software and storing in the database  I want to upload a software(may be of maximum 20mb) through JSP, and store it in the database. The coding present in the site for uploading and storing in the database
image on submit button
image on submit button  i need to set an image on submit button. In javascript we can create a button like.. <a href="javascript:;" class="button...: transparent; cursor: pointer; or input[type=submit] { background: transparent
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
On Click on Submit Button Display Data on Orderlist
On Click on Submit Button Display Data on Orderlist  How can retreive data from database on orderlist on Click on submit Button of same page
storing xml into database - XML
storing xml into database   hi i have an xml file it contains elements with attributes as well as nested elements so how to go forward .......with it i know how to persist a simple xml file into data base but i m finding some
Get specific item details by clicking on hyperlink
Get specific item details by clicking on hyperlink  sir, I am... button, if I click on that button it lists all items with item name and corresponding image with a hyperlink on it from the database to a jsp page. -If I click
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp
after entering details in reg page,n enter the submit button,how can v store... registration page n login page. after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm
How to Display Next question from database after clicking Next Button using "Arraylist concept"
How to Display Next question from database after clicking Next Button using "Arraylist concept"  </tr> <%if (pageName.equals("1")) {%> <tr> <td> <div style
Disabling submit button using jQuery
Disabling submit button using jQuery  Hello Sir I want to know - is there any way or approach to disable client side form's "Submit" button. Please give code also.ADS_TO_REPLACE_1   For all submit buttons, via JQuery
How can we submit a form without a submit button?
How can we submit a form without a submit button?  How can we submit a form without a submit button
Click On Images of Submit Button Perform Action
Click On Images of Submit Button Perform Action  I have login page in which insert of submit button i used image. Therefor on Click of image i have to validate form , link with database and goto the next page
Hide text by clicking button
Hide text by clicking button In this tutorial, we will discuss about hide/show text by clicking on button. In the below example, there are two buttons... clicking any button : ADS_TO_REPLACE_4 After click "Hide" button
Struts application two submit button
;/html> Here am using two submit button one is login and another one is new...Struts application two submit button  Hai, i'm new in struts...;html:submit tabindex="6" styleClass="btTxt"> <bean
Compose mail by clicking on send mail button
Compose mail by clicking on send mail button  How i get microsof out look page opend for composing mail by just clicking on send mail button and when outlook page open then in to:my email id is written on my jsp page
to fetch data from ms word and storing into database
to fetch data from ms word and storing into database  i want to know how to fetch datafields from ms word and storing into database??? please answer soon .its urgent
Storing records of a file inside database table in java
Storing records of a file inside database table in java  Here is my... surya 25 4 3 ashok 27 I have to display a browse button and whenever user selects student.csv and clicks on submit button, i have to store
Should not logout after clicking the back/forward button
Should not logout after clicking the back/forward button  Hi all I... he clicks on the back button user automatically gets logged out. very next if clicked the forward button user gets logged in..!! how can I solve this issue? What
getting and storing dropdown list in database in jsp
getting and storing dropdown list in database in jsp  i have a drop down list to select book from database. i'm able to retrieve dropdown list from... lyk this. but it storing null value in the database. :\ what to do
retrieve the data to text fields from database on clicking the value of combo box
getting data into textarea from database table by clicking on the button...retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking
Toggle hide/show by clicking same button
Toggle hide/show by clicking same button In this tutorial, we will discuss about how to toggle hide/show by clicking button. In the given below 2 example, there is button ,by clicking on it, the paragraph will hide/show . In first
how to disable submit button after login in jsp
how to disable submit button after login in jsp  Hi, I have... on the back button in browser it stars displaying login page. How to prevent this? how to disable submit button after login in jsp? Thanks   Hi, You can
Write an applet program to transfer the content of the text field into the component on clicking a button
Write an applet program to transfer the content of the text field into the component on clicking a button  Write an applet program to transfer the content of the text field into the component on clicking a button
complex xml parsing and storing in database - XML
complex xml parsing and storing in database  Hi Experts ,i want to parse my xml document and store it in mysql database. This is my code. How to parse this complex data. EDI_DC40 800 0000000000557748
storing records which of a file into a table of mssql database
storing records which of a file into a table of mssql database  I have a requirement like this, A file contains some records with headers same as column names of a table. I have to store those records into a table
how to display the values of one list in other upon clicking a button in struts2
how to display the values of one list in other upon clicking a button in struts2  Hello friends..Am new to struts2..Please any one has to guide me... list upon clicking a button...Can any one provide me the sample code.. Hope
getting problem in storing & retrieving value in database
getting problem in storing & retrieving value in database  Hello everyone i am doing a project where my back end is ms access & i want to store value like 5353250214 so if i store it as long int in access it wont take it &
Change paragraph by clicking button(Toggle effect)
Change paragraph by clicking button(Toggle effect) In this tutorial, we will discuss about how to change paragraph by clicking button using jQuery...;ADS_TO_REPLACE_1 OUTPUT After clicking "toggle " button :ADS
Write a program to get student details and store in a database
Write a program to get student details and store in a database  Write a program to get student details and store in a database
how to access the object of one frame on clicking a button without using this keyword
how to access the object of one frame on clicking a button without using... extends Frame { public static void main(String args[]) { Button b1... Button("Yellow"); mb.add(b1); mb.add(b2); mb.add(b3
JSP to add details to a database from a HTML form.
JSP to add details to a database from a HTML form.  Hi I'm a second year CS student who has to use JSP to validate a HTML form and add the details entered into a database. The files are all in one folder for use in tomcat
Facing Problem with submit and cancel button in same page - Struts
Facing Problem with submit and cancel button in same page  Hi, can u please help me out.I have placed submit and cancel button in the jsp page but i am unable to know how to write the form and action classes   Hi
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
and subsequently clicking button in java swing application  Hello Sir, first of all... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
and subsequently clicking button in java swing application  Hello Sir, first of all... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
and subsequently clicking button in java swing application  Hello Sir, first of all... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
PHP HTML Form Submit Button
Topic : HTML FORM SUBMIT BUTTON Part - 4 The another part which is important to covered that is Submit button. If you are following all the previous parts.... The Submit button in Html is used to submit form data to the page mentioned
reading the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database table  Here is my requirement, I want to read the records from a .xlsx file and store that records in database table. I tried like this public class
how to disable submit button in jsp using servlet when some condition is satisfied
how to disable submit button in jsp using servlet when some condition is satisfied  how to disable submit button in jsp using servlet when some condition is satisfied
Autopopulate values into textbox from database on pressing tab or on clicking
Autopopulate values into textbox from database on pressing tab or on clicking  Hi, In my project we have to enter a productid which is first need to be searched into database. if it already exists then it will autopopulate its

Ads