I want to add data dynamically for that which methods i have to use to retrieve the dynamic data .
February 8, 2010 at 5:03 PM
Hi Friend,
Try the following code:
1)get.jsp:
<html>
<form method="post" action="../InsertAndRetrieveData">
<table>
<tr><td>Enter Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
2)InsertAndRetrieveData.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class InsertAndRetrieveData 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 address=req.getParameter("address");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root","root";);
Statement st=con.createStatement();
int i=st.executeUpdate("insert into data(name,address) values('"+name+"','"+address+"')");
st.close();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from data");
while(rs.next()){
out.println(rs.getString("name")+" "+rs.getString("address")+"<br>");
}
st.close();
}
catch(Exception e){}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{doPost(req,res);}
}
Thanks
Related Tutorials/Questions & Answers:
Doubt in servlets - JSP-ServletDoubt in servlets Good Evening sir/madam,
I want to add data dynamically for that which methods i have to use to retrieve... the following link:
http://www.roseindia.net/
servlets/index.shtml
Thanks
doubt thisdoubt this what is the use of "this" and "super" keyword
Advertisements
DOUBT ?DOUBT ? in c++ member function of a class must be public
DoubtDoubt how to submit the details and how to go the next page after submitting.please clarify my
doubt I don't know how to submit details
DoubtUser request form how to submit the details and how to go the next page after submitting.please clarify my
doubt I don't know how to submit details.
1)page1.html:
<html>
<form type=get action="page2.html
DoubtHow to load page how to submit the details and how to go the next page after submitting.please clarify my
doubt I don't know how to submit details.
1)page1.html:
<html>
<form type=get action="page2.html
DoubtSubmit and process form how to submit the details and how to go the next page after submitting.please clarify my
doubt I don't know how to submit details.
1)page1.html:
<html>
<form type=get action
Doubtload next page after submitting how to submit the details and how to go the next page after submitting.please clarify my
doubt I don't know how to submit details.
1)page1.html:
<html>
<form type=get action
servletsservlets what is the duties of response object in
servlets servletsservlets why we are using
servlets servletswhat are advantages of servlets what are advantages of
servlets
Please visit the following link:
Advantages Of
Servlets ServletsServlets How to edit and delete a row from the existing table in
servlets servletsservlets How do you communicate between the
servlets?
We can communicate between
servlets by using RequestDespatcher interface and servlet chaining
servletswhat is the architecture of a
servlets package what is the architecture of a
servlets package
The javax.servlet package provides interfaces and classes for writing
servlets.
The Servlet Interface
The central
ServletsServlets How to check,whether the user is logged in or not in
servlets to disply the home page
Servlets.
Anyways, please visit the following links:
http://www.roseindia.net/
servlets/introductiontoconfigrationservlet.shtml
http://www.roseindia.net/
servlets servletsservlets why we require wrappers in
servlets? what are its uses?
Please explain
These wrappers classes help you to modify request...://www.roseindia.net/
servlets/response-filte.shtml
servletsservlets How to open and read the contents of a text file in
servlets?
Please visit the following link:
Read text file using Servlet
servlets servlets Hi
what is pre initialized
servlets, how can we achives?
When servlet container is loaded, all the
servlets defined in the web.xml file does not initialized by default. But the container receives
servletsservlets why do we need web-inf directory in web application why do we need web-inf directory in web application? means what's the benefits of doing so
Servlets and Servlets and Sir...! I want to insert or delete records form oracle based on the value of confirm box can you please give me the idea.... thanks
servletswhich are the differ ways you can communicat between servlets which are the differ ways you can communicat between
servlets
Different ways of communicating between
servlets:-
1)Using RequestDispatcher object.
2
servlets package supports the development of
servlets that use the HTTP protocol. The classes... javax.servlet.GenericServlet and serves as the base class for HTTP
servlets. HttpServlet-Request
servletswhat are sessions in servlets what are sessions in
servlets
A Session refers to all the request that a single client makes to a server...:
http://roseindia.net/jsp/jspsession/
http://www.roseindia.net/
servlets the servletswhat is diff between generic
servlets and httpservlets what is diff between generic
servlets and httpservlets
Difference between GenericServlet and HTTPServlet:
1)GenericServlet belongs to javax.servlet package
servlets regarding the user usage and habits.
Servlets sends cookies to the browser client...://www.roseindia.net/jsp/jspcookies.shtml
http://www.roseindia.net/
servlets/use
servletsservlets hi i am using
servlets i have a problem in doing an application.
in my application i have html form, in which i have to insert on date value, this date value is retrieved as a request parameter in my servlet
servletswhat are filters in java servlets what are filters in java
Filters are powerful tools in servlet environment. Filters add certain functionality to the
servlets apart from processing request and response paradigm
servletsservlets what are different authentication options available in
servlets
There are four ways of authentication:-
HTTP basic authentication
HTTP digest authentication
HTTPS client authentication
Form-based
Validation doubtValidation doubt hi.....
thanks for the other validation code. I have got that and implemented in my code but i have a
doubt in that.
As we try... think i am able to tell u what i want to and u have got whats my
doubt.
plz give
doubt on DAO'sdoubt on DAO's hai frnds....
can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin?????
and please help me.
how to use dao s while integrating
doubt on DAO'sdoubt on DAO's hai frnds....
can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin?????
and please help me.
how to use dao s while integrating
doubt in struts - Strutsdoubt in struts i don't understand the concept on Resource bundle in struts can u please help me out
String doubt replace functionString
doubt replace function What is the output and why of below :
String s1 = "Hello";
if(s1.replace('H','H')== "Hello")
System.out.println("yes");
else
System.out.println("No");
if(s1.replace("H", "H")== "Hello
doubt regarding JSFdoubt regarding JSF Hi,
pls explain what is difference between struts &JSF?
pls explain what is difference between SPRING &JSF
jsp -servletsjsp -servlets i have
servlets s1 in this
servlets i have created emplooyee object, other
servlets is s2, then how can we find employee information in s2
servlets "Doubt on Swing" - Java Beginners"
Doubt on Swing" Hi Friend....
Thanks for ur goog Response..
i need to create a GUI Like...
pic1.gif RadioButton
pic2.gif RadioButton
Pic3.gif RadioButton
If we have select d appropriate radio
Doubt Regarding ChartsDoubt Regarding Charts Hi,
Can you please help me out by answering "hoe to include charts in core java code and struts code"
thanks in advance,
Swaroop Eswara
Please visit the following link:
Jfreechart
Servlets with ExtjsServlets with Extjs how to integrate
servlets and extjs and also show database records in extjs grid using servlet how to get
servlets json response. Can any one please help me
Doubt in struts - StrutsDoubt in struts I am new to Struts, Can anybody say how to retrieve data from database and display it in jsp. Some said to use beans but i dont know how to do. Please help me in this regard. It will be helpful, if explained