File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Html-Database-servlet(Urgent!!!!!!!!!!!!!!!!!!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Html-Database-servlet(Urgent!!!!!!!!!!!!!!!!!!)" Watch "Html-Database-servlet(Urgent!!!!!!!!!!!!!!!!!!)" New topic
Author

Html-Database-servlet(Urgent!!!!!!!!!!!!!!!!!!)

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
i have a problem!!!
i have to store the data from the form through the servlet to the database.
i have used the generic servlet but the method is only ont enumeration for all the enteries from the form but when i sconnect to the database through the servlet how do it will enter the data intro the respective field columns.
please reply back fast
vikas chadha
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You have to use HttpServlet for this purpose and use prepared statement for populating data into database.
Bye for now ...
vivek nehra
vivek_nehra@hotmail.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
The easiest thing is to give the form fields names that match the database fields. Then you extract the data from the user HttpRequest object with getParameter( name )
The Enumeration you get from getParameterNames() just enumerates the field names, the values are not there.
Bill
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
In continuation to the first reply u have recieved.
Please use HttpServlet and Prepared statement.
I am giving you a sample code which may be of some help to you :
uname=req.getParameter("username"); //username & pass are name pword=req.getParameter("pass"); // of your form fields

PreparedStatement psmt=con.prepareStatement("Select * from table1 where name1=?");
psmt.setString(1,uname);
rs=psmt.executeQuery();
Bye,
doshi_milan@yahoo.com
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
In continuation , to my reply above ( which was for getting data from database; the undermentioned code is for inserting(populating) into the database)
uname=req.getParameter("username"); //username & pass are name pword=req.getParameter("pass"); // of your form fields

PreparedStatement psmt=con.prepareStatement("Insert into table1 values(?, ?)");
psmt.setString(1,uname);
psmt.setString(2,pword);
psmt.executeUpdate();
Bye,
doshi_milan@yahoo.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Html-Database-servlet(Urgent!!!!!!!!!!!!!!!!!!)