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
Ads
Related Tutorials/Questions & Answers:
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
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" />
<
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
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
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
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
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.
For all
submit buttons, via JQuery, it'd
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
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
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
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
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
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