PostgreSQL connection in Java Servlet to Retrieve Information from the DB. Getting Error

前端 未结 3 976
一生所求
一生所求 2021-01-07 07:21

I am having difficulty with getting this work. I can connect to the database without problem, however I can not make it show me the html page. It does not run.



        
相关标签:
3条回答
  • 2021-01-07 07:51

    I get the following error any body knows why?

    The reason why you are getting that error body is that your handler for ClassNotFoundException is throwing away the original exception stacktrace. You are writing the original exception's message to System.err but (obviously) that won't go into the normal system logs. (You'll probably find find the message in the "catalina.out" file ... depending on how Tomcat is configured / launched.)

    The right way to do this is to either chain the exception; e.g.

        throw new ServletException("Class not found Error", e);
    

    or log it explicitly at the point that you catch it. And if you do log it explicitly, make sure that you log the exception, and not just the exception message.


    We can't tell you the actual root cause of the problem unless we see the original exception stacktrace ... but the two most likely causes are:

    • The classloader can't find a class that is needed; e.g. because the JAR file is not in the right place.
    • Class initialization failed for some class during the initialization of the class that you are attempting to load.
    0 讨论(0)
  • 2021-01-07 07:51

    Tomcat expects that your servlet will be in a package. Yours appears to be in the default package; please add one and recompile. I'll bet things will go better for you then.

    Tomcat 6 and 7 expect to find JDBC JARs in the server /lib directory. Add your PostgreSQL JDBC JAR to the server /lib location.

    0 讨论(0)
  • 2021-01-07 07:55

    Seem you did't add Postgresql JDBC driver into classpath, as the following error suggest:

    javax.servlet.ServletException: Class not found Error
    

    Which is origin from:

    throw new ServletException("Class not found Error");
    

    You can download Postgresql JDBC driver and put in PROJECT/WEB-INF/lib folder.

    Suggestion

    One suggestion, your exception handling is wrong, you should change

    throw new ServletException("Class not found Error");
    

    to

    throw new ServletException("Class not found Error", e);
    
    0 讨论(0)
提交回复
热议问题