Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic