More information-I am closing the connection,statement and result set.My program is below:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class SearchServlet extends HttpServlet
{
//shared by all the requests
Statement st;
Connection dbConn;
String word;
public void init(ServletConfig config) throws
ServletException{
super.init(config);
try
{
//load jdbc-odbc bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//establish database connection to netsparsh
dbConn=
DriverManager.getConnection"jdbc
dbc:netsparsh");
System.out.println("connection established");
}
//thrown by Class.forName
catch(ClassNotFoundException e)
{
System.out.println("JDBC-ODBC bridge not found");
return;
}
catch(SQLException e)
{
System.out.println("SQL Exception thrown!");
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
try
{
System.out.println("in doPost method");
res.setContentType("text/html");
//get handle to output stream
PrintWriter out=res.getWriter();
out.println("<HTML>");
out.println("<BODY>");
word=req.getParameter("address");
//create statement
st=dbConn.createStatement();
//query database for result set
String query="select membership_no,name,url from member where lcase(name)='"+(word)+"' ";
ResultSet rs=st.executeQuery(query);
if(rs.next()==true) {
String temp="http://";
String temp1=rs.getString("url");
res.sendRedirect(temp+temp1);
}
else
out.println("NO URL Found");
out.println("</BODY>");
out.println("</HTML>");
rs.close();
st.close();
out.close();
dbConn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public String getServletInfo()
{
return "SearchServlet........and enjoy!";
}
}