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









Related Tutorials/Questions & Answers:
Programming in JDBC and JSP - JSP-Servlet
Programming in JDBC and JSP  Write a program using JDBC and JSP to display the names and addresses of all those MCA students at your study centre who have completed/submitted their theory assignments of all the courses of IV
how to run jdbc in jsp program - JSP-Servlet
how to run jdbc in jsp program  i want to use sql server 2005 in jsp... visit the following links: http://www.roseindia.net/jsp/submit-comments-database.shtml http://www.roseindia.net/jsp/prepared-statement-query.shtml Hope
Advertisements
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
JSP and JDBC - JSP-Servlet
JSP and JDBC  Respected sir/Madam, I am R.Ragavendran.. I am in urgent need of programming from roseindia team.. My requirement... for JDBC codings must be present.. NOTE: When User clicks Insert,for example
jdbc,jsp - JDBC
jdbc,jsp   this is my jsp code in this code i have to give hyperlink to database(selected row must be deplay)  Hi keerthi, replace the line
JDBC in JSP - JDBC
JDBC in JSP   Sir, This is the code showing the problem. regards sreejith
JDBC in JSP - JDBC
JDBC in JSP   Sir, This is the code showing the problem. regards sreejith
JDBC in JSP - JDBC
JDBC in JSP  Sir, I got a problem in my jsp page which contains a delete query to delete the fields from MySql DB. The delete query is working.... Regards Sreejith  send me your jsp coding then i can understand what
jsp,beans,jdbc - JSP-Servlet
jsp,beans,jdbc  I have created jsp page and corresponding servlet... database for specific date .this data is retrived on jsp page by beans.i use beans... in jsp how to show field sum on jsp page plz guide   Hi friend
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...\\myjdbcfile.csv"; Connection conn = null; String url = "jdbc:mysql://localhost:3306
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.
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
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
Requiring Guidance - Java Magazine
Requiring Guidance  Sir, I have finished my core java after that others topic that i have covered are: Servlets JSP JDBC Swing RMI what... be Swing, jdbc, jsp, servlet after RMI. Thanks.  Can you throw
java - JDBC
sending data inserting code into database using JDBC with jsp... have to use JDBC and oracle. plz send the details for connecting "java... for database connectivity: http://www.roseindia.net/jdbc/jdbc-mysql
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
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
JEE 5 Tutorial
like JSE, XML, JDBC, JSP, Sevlets etc...  JEE is offering new
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
JSP,JDBC and HTML(Very Urgent) - JSP-Servlet
JSP,JDBC and HTML(Very Urgent)  Respected Sir/Madam, Thanks... details from database using JDBC and JSP. The home page i.e HTML Page must contain... the code: I am not using any html. I used only jsp & jdbc. HOme Page
New to programming...
to learn is the JDBC, JSP, Servlets, MySQL Database and then the software
CORBA and RMI Books
.     CodeNotes for J2EE: EJB, JDBC, JSP, and Servlets CodeNotes provides the most succinct, accurate... between comprehensive manuals and pocket reference.CodeNotes for J2EE: EJB, JDBC
JSP Examples
file in JSP   Export Data into CSV file uing JDBC in JSP   Download...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
JavaBean properties in JSP | Update Database Table using JDBC in JSP... Map | Business Software Services India JSP Tutorial Section  Intro to JSP | JSP Technology | JSP Architecture | JSP Actions | JSP tags
JSP Tutorials
; In this section, you will learn how to export data into CVS file using JDBC in jsp... JSP Tutorials       JSP Tutorials and examples, you will find many examples

Ads