• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html and servlet with jdbc

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u for the reply!
i am being plagued by another programming problem
my programme code is as under the problem is only name parameter takes value and rest of the variables remain empty.
Pl point out 2 me where the problem lies.i would b greatly obliged.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.* ;
import java.util.*;
import java.sql.*;
public class projectform2 extends HttpServlet
{
Connection c=null;
Statement s=null;
ResultSet r=null;
PreparedStatement ps=null;
String Name=" ";
String Address1=" ";
String Address2=" ";
String EMail=" ";
String Qualification=" ";
String CompanyName=" ";
String Designation=" ";
String Comments=" ";

public void init(ServletConfig con) throws ServletException
{
super.init(con);
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
PrintWriter o=res.getWriter();
res.setContentType("text/html");
Enumeration e=req.getParameterNames();
o.println("<html>");
o.println("<head>");
o.println("<title>User Information</title>");
o.println("<head>");
o.println("<body>");
while(e.hasMoreElements())
{
String str=(String)e.nextElement();
System.out.println("the str is"+str);
if(str.equals("Name"))
{
String Name=req.getParameter(str);
System.out.println("the name is"+Name);
}
else if(str.equals(Address1))
{
System.out.println("excep");
String Address1=req.getParameter(str);
System.out.println("the address is"+Address1);
}
else if(str.equals(Address2))
{
String Address2=req.getParameter(str);
System.out.println("the address is"+Address2);
}
else if(str.equals(EMail))
{
EMail=req.getParameter(str);
System.out.println ("the email is"+EMail);
}
else if(str.equals(Qualification))
{
System.out.println("the qual is");
Qualification=req.getParameter(str);
System.out.println("the qual is"+Qualification);
}
else if(str.equals(CompanyName))
{
CompanyName=req.getParameter(str);
System.out.println("the comp is"+CompanyName);
}
else if(str.equals(Designation))
{
Designation=req.getParameter(str);
}
else if(str.equals(Comments))
{
Comments=req.getParameter(str);
}
System.out.println(""+Name+""+Address1+""+Address2+""+EMail);
}
System.out.println(""+Name+""+Address1+""+Address2+""+EMail);
if(Address1.equals(" ")| |Name.equals(" ")| |EMail.equals(" ")| |Qualification.equals(" ")
| |Comments.equals(""))
{
System.out.println ("the name is"+Name);
o.println("<b>Please type the requisite details!</b>");
o.println("<p>");
o.println("<b>Please press the back button to go back.</b>");
}
else if(EMail.indexOf('@')==-1)
{
System.out.println ("the email is"+EMail);
o.println("<b>Please type a valid E-Mail ID.</b>");
o.println("</body>");
o.println("</html>");
}
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1){System.out.println("excep"+e1);}
try
{
c=DriverManager.getConnection("jdbc dbc:spicdsn");
if(c!=null)
{
s=c.createStatement();
ps=c.prepareStatement("Insert into Table1(Name,Address1,Address2,EMail,Qualification,CompanyName,Designation,Comments) values(?,?,?,?,?,?,?,?)");
ps.setString(1,Name);
ps.setString(2,Address1);
ps.setString(3,Address2);
ps.setString(4,EMail);
ps.setString(5,Qualification);
ps.setString(6,CompanyName);
ps.setString(7,Designation);
ps.setString(8,Comments);
int r1=ps.executeUpdate();
}
}
catch(SQLException e2){System.out.println("excep"+e2);}
o.println("<b>");
o.println("Thank you for your valuable feedback!");
o.println("Dear"+Name+"we will try to incorporate your advice in our better functioning as soon as possible");
o.println("</b>");
o.println("</body>");
o.println("</html>");
}
}
}
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
If u can post the error messages that will help to find out the problem.so do post the error messages
regards
raghav
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets take one case...
"else if(str.equals(Designation))"
The parameter name should be in double quotes.
What ur program currently does is tries to compare the string element passed from html with a variable Designation whose value has been initialized to empty string. Hence the problem.
Do change all the comparisons to String values as "else if(str.equals("Designation"))" and lemme know if the solution was as simple as this.
cheers,
mpr
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic