my dog learned polymorphism*
The moose likes Servlets and the fly likes html and servlet with jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "html and servlet with jdbc" Watch "html and servlet with jdbc" New topic
Author

html and servlet with jdbc

Mala Raman
Greenhorn

Joined: Aug 11, 2001
Posts: 2
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>");
}
}
}
Raghav
Greenhorn

Joined: Jul 24, 2001
Posts: 14
hi,
If u can post the error messages that will help to find out the problem.so do post the error messages
regards
raghav
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
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
 
jQuery in Action, 2nd edition
 
subject: html and servlet with jdbc