• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem retrieving data from database using servlets

 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please help me with this problem.The program is about retrieving data from Oracle database using servlets on javawebserver2.0.When I type the url http://localhost:8080/servlet/HttpEx2 It says "The page cannot be displayed."
Can someone check this and point out where I am wrong?
The program is given below.
Any help is greatly appreciated.
Thanks.
Aparanji.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class HttpEx2 extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
ServletOutputStream out=res.getOutputStream();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:divya","scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student");
out.println("<html><body bgcolor=olive text=yellow>");
while(rs.next())
{
String s1=rs.getString(1);
int i1=rs.getInt(2);
int i2=rs.getInt(3);
out.println(s1+" "+i1+" "+i2+"<br>");
}
rs.close();
st.close();
con.close();
out.println("</body></html>");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
 
Somas kanthan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Are you calling your servlet directly then you have to move the code to doGet method. Because doGet is the default method which is called, Otherwise in the HTML or calling page you need to give the method as Post.
Hope this works..
 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Somas,
Your suggestion worked.I put doPost because I thought Post was used for unlimited data and used that method.
Thank you.
Aparanji.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic