Hi,
I am new to
servlets and I am using javawebserver2.0. I have written a program which si going to use the database wich is in mycase a text file and I am trying to use the database abut I am not being able to. The program is getting compiled but when I try to run it is showing a 501 error. I am attaching the program alongwith.I need urgent help on this.
thankximport java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.*;
public class ServletA extends HttpServlet
{
Connection dbcon;
public void init() throws ServletException
{
try
{
String driver = getInitParameter("JdbcDriver");
String dbURL = getInitParameter("dbURL");
Class.forName(driver);
dbcon = DriverManager.getConnection(dbURL,"","");
}
catch (ClassNotFoundException e)
{
System.out.println("DB Driver not found");
System.out.println(e.toString());
throw new UnavailableException(this, "DB Driver class");
}
catch (SQLException e)
{
System.out.println("Error in connect");
System.out.println(e.toString());
throw new UnavailableException(this, "Cannot connect");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Search Results</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
try
{
Statement st=dbcon.createStatement();
ResultSet rec=st.executeQuery(
"Select Item_Name,Item_Number "+
"from Items");
while(rec.next())
{
out.println("Item_Name:" + rec.getString("Item_Name"));
out.println("Item_Number:" + rec.getString("Item_Number"));
}
st.close();
}
catch(Exception e)
{
}
out.println("</BODY></HTML>");
out.close();
}
}
,
dp