• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

servlet-jdbc - internal servlet error (error:500)

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am trying a small program on interaction with jdbc and servlet , I am having a html page with a button , which when pressed invokes a servlet through post method which prints out a list of book in the database with its author,isbn etc. when i load the html page and click the button , i get a error error:500 ,the error looks as following:
Error: 500
Internal Servlet Error:
java.lang.IllegalAccessException: booklist
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.web.core.ServletWrapper.loadServlet(ServletWrapper.java:90)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:109)
at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
at com.sun.web.core.Context.handleRequest(Context.java:375)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:135)
if any body can solve the problem ,i would be great , i am running the program on win98,jsdk2.1 and jdk1.3
thanks
raghav
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the error 500 means that your servlet has been found but some error ocurred in it. Problably your servlet has some error or some code it references has it. If you publish the code it�s gonna be easyer to help.
 
Raghav
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am attaching the code of the html page calling the servlet and the servlet code ,please help me with the problem
html page code:
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="http://localhost:8080/examples/servlet/booklist">
<p><input type="submit" value="ShowBooks" name="B1"></p>
</form>
</body>
</html>
servlet code:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class booklist extends HttpServlet
{
Connection dbconn;
Statement st;
ResultSet rs;
PrintWriter pw;
public void init(ServletConfig cfg) throws ServletException
{
try
{
super.init(cfg);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbconn=DriverManager.getConnection("jdbc dbc:bookstore");
}
catch(SQLException se)
{
}
catch(ClassNotFoundException ce)
{
}
}
//public void service(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
//{
//doPost(request,response);
//}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
try
{
st=dbconn.createStatement();
String query = "Select a.lastname,a.firstname,b.isbn,c.title,d.name from authors a,auth_books b, books c,publishers d where a.authid=b.authid AND b.isbn = c.isbn AND c.pub_code = d.pub_code";
rs = st.executeQuery(query);
response.setContentType("text/html");
pw = response.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("<title>");
pw.println("List of Books ");
pw.println("</title>");
pw.println("</head>");
pw.println("<body bgcolor = lightblue>");
pw.println("<table border=1>");
pw.println("<tr><th>ISBN</th><th>Title</th><th>Author</th><th>Publisher</th></tr>");
while(rs.next())
{
pw.println("<tr>");
pw.println("<td>");
pw.println(rs.getString("isbn"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("title"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("lastname")+""+rs.getString("firstname"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("name"));
pw.println("</td>");
pw.println("</tr>");
}
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
}
catch(SQLException se1)
{
}

}
public void destroy()
{
try
{
pw.close();
rs.close();
dbconn.close();
}
catch(Exception e){}
}
}
thanks for the help
raghav
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First check if you corrected register the jdbc dbc:bookstore in the control panel Data Sources, than check all the columns names and types you�re trying to recover from the database (i.e rs.getString("isbn"),etc), and don�t let the catch statements empty, allways print the stackTrace and or getMessage ex:
catch(SQLException sqle)
{
sqle.printStackTrace();
System.out.println(sqle.getMessage());
}
and check the server console window.
 
Raghav
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i checked all the thing still i am getting the Error:500 thing ,Internal Servlet Exception , it says it is a illegalaccessexception, i tried the same code as a jdbc application it worked fine , but when used with servlet its giving trouble , what can be the problem be , any way thanks for your help
raghav
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to pass a login and password even empty to the database ex:
Connection con = DriverManager.getConnection(url,
"yourLogin", "yourPassword");
or

Connection con = DriverManager.getConnection(url,
"", "");
cause looks like it�s asking for one
 
Raghav
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
great man , after i give the blank username and password in the parameter it has started working , was it the javasecurity policy which was stopping it . But when i run it as a application it works fine .any way thanks man , will be back with more queries.
raghav
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

man!!!
looks like you are cheating on us.......how could you....
stick to javaranch and get your solutions....
Heheheh.....just kidding!
- satya
reply
    Bookmark Topic Watch Topic
  • New Topic