jdbc-jsp

jdbc-jsp

<html>
<head>
<title>your info mail</title>
</head>
<body bgcolor=#FAEBD7>
<center><u><font color=#1f2e3c>your info mail</font></u></center>

<form action="/Insertinfo" method="post">
<table align=center border=0 cellspacing=0 cellpadding=10 width=100 height=0 bgcolor=#faebd7
<tr>
<td>Name</td>
<td><input type=text name=ID size=20></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name=IDno size=10></td>
</tr>
<tr>
<td>Address</td>
<td><input type=text name=ID size=30></td>
</tr>
<tr>
<td>tel no</td>
<td><input type=text name=telno size=20></td>
</tr>
<tr>
<td>sex</td>
<td><input type=radio name=s value="MALE">
<input type=radio name=s value="FEMALE"></td>
</tr>
<TR>
<td>country</td>
<td><select name="Country Name">
<OPTION VALUE ="I">India</OPTION>
<OPTION VALUE ="C">Canada</OPTION>
<OPTION VALUE ="f">france</OPTION>
<OPTION VALUE ="a">America</OPTION>
</select>
</td>
</table>
<br>
<br>
<center>
<input type=submit name=submit value=submit>
<input type=reset name=reset value=clear>
</center>
</form>
</body>
</html>

I have this information in html please let know how to insert information into database using jsp

View Answers

January 3, 2011 at 2:43 PM

hi shwetappatil,

               use the names like

String str1=request.getParameter("ID");
here id refers to the name of the input field and know you are storing it in str1. like this store all the field into some strings and insert into database but the field names should be different while giving. You had used same name for name and address.check that and continue.


January 4, 2011 at 5:01 PM

Hi Friend,

Try the following code:

1)form.jsp:

<html>
<head>
<title>your info mail</title>
</head>
<body bgcolor=#FAEBD7>
<h1><center><u><font color=#1f2e3c>your info mail</font></u></h1></center></p>

<form action="../InsertServlet" method="post">
<table align=center border=0 cellspacing=0 cellpadding=10 width=100 height=0 bgcolor=#faebd7>
<tr>
<td>Name</td>

<td><input type=text name="name" size=20></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name="pass" size=10></td>
</tr>
<tr>
<td>Address</td>
<td><input type=text name="address" size=30></td>
</tr>
<tr>
<td>Tel no</td>
<td><input type=text name="no" size=20></td>
</tr>

<tr>
<td>Sex</td>
<td><input type=radio name="gender" value="MALE">M
<input type=radio name="gender" value="FEMALE">F</td>
</tr>
<TR>
<td>Country</td>
<td><select name="country">
<OPTION VALUE ="India">India</OPTION>
<OPTION VALUE ="Canada">Canada</OPTION>
<OPTION VALUE ="France">France</OPTION>
<OPTION VALUE ="America">America</OPTION>

</select>
</td>
</table>
<br>
<br>
<center>
<input type=submit name=submit value=submit>
<input type=reset name=reset value=clear>
</center>
</form>

<p></body>
</html>

2)InsertServlet.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class InsertServlet extends HttpServlet { 
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String name=req.getParameter("name");
        String pass=req.getParameter("pass");
        String address=req.getParameter("address");
int no=Integer.parseInt(req.getParameter("no"));
String gender=req.getParameter("gender");
String country=req.getParameter("country");
try{
Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into mail(name,password,address,telno,gender,country) values('"+name+"','"+pass+"','"+address+"',"+no+",'"+gender+"','"+country+"')");
         out.println("Data is inserted successfully");
         con.close();
        }
catch(Exception e){
    System.out.println(e);
}
            }
        }

Thanks

Ads









Related Tutorials/Questions & Answers:
jdbc-jsp
jdbc-jsp  <html> <head> <title>your info mail</title> </head> <body bgcolor=#FAEBD7> <center><u>... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
JDBC with JSP
JDBC with JSP  how to get a combo box value and pass it to the java method in a jsp program dynamically, without moving to servlet or next page
Advertisements
Export Data into CSV file uing JDBC in JSP
Export Data into CSV file uing JDBC in JSP       CSV file : A CSV file is commonly known... url = "jdbc:mysql://localhost:3306/"; String dbName = "user_register"; String
Update Database Table using JDBC in JSP
Update Database Table using JDBC in JSP... the existing  record of mysql table using jdbc connectivity in the jsp page. In this example we have created two jsp pages update.jsp and updatingDatabase.jsp.
need a sample project using java technologies like jsp, servlets, struts
need a sample project using java technologies like jsp, servlets, struts  Hi everybody! I have learnt core java,jdbc,jsp,servlets & struts. Please guide me where can i find sample project like library management, CMS or any
question
in Jdbc -jsp page . that's it. chandu
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP and servlets on roseindia.net Now I want to learn Spring Framework because many
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP and servlets on roseindia.net Now I want to learn Spring Framework because many
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP and servlets on roseindia.net Now I want to learn Spring Framework because many
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP and servlets on roseindia.net Now I want to learn Spring Framework because many
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP and servlets on roseindia.net Now I want to learn Spring Framework because many
What is difference between Core Java and Advanced Java?
Reflection JDBC JSP Tutorials Servlet Tutorials So, above tutorials will help you... topics includeing JSP and Servlets which is necessary to develop web applications
What is difference between Core Java and Advanced Java?
Reflection JDBC JSP Tutorials Servlet Tutorials So, above tutorials will help you... topics includeing JSP and Servlets which is necessary to develop web applications
Java Developer Training
, JDBC, JSP, Hibernate, Struts, Java Framework, etc. These are the advance
New to programming...
to learn is the JDBC, JSP, Servlets, MySQL Database and then the software
JSP Examples
into CSV file uing JDBC in JSP   Download CSV File from Database in JSP...JSP Examples In this section we will discuss about the examples of JSP. This section will help you create web applications using JSP. In this page you
Sitemap JSP Tutorial Section
uing JDBC in JSP | Download CSV File from Database in JSP  JSP... | Update Database Table using JDBC in JSP | XML File using DOM parser... Map | Business Software Services India JSP Tutorial Section  Intro

Ads