I am using Tomcat as a server to work on a servlet that need to access a database and I need to use CachedRowSet, but I cannot seem to connect to the database correctly.

Currently I have

public class FaqListingServlet extends HttpServlet 
   private CachedRowSetImpl cachedRowSet;
   // set up database connection and create SQL statement
  public void init( ServletConfig config ) throws ServletException
      // attempt database connection and create Statement
      	//CachedRowSetImpl cachedRowSet = new CachedRowSetImpl();
      	cachedRowSet.setCommand("SELECT * FROM topics");
      } // end try
      // for any exception throw an UnavailableException to 
      // indicate that the servlet is not currently available
      catch ( Exception exception ) 
         throw new UnavailableException( exception.getMessage() );
      }// end catch
   }  // end method init

where the "databaseDriver", "databaseName", "password" etc. are all declared in an xml file. Currently though it always dumps an exception because it never successfully makes the connection. I am assuming it is my implementation of the CachedRowSet that is incorrect so any suggestions would be appreciated.

Also does anyone know why tomcat would suddenly not display the tomcat homepage? I get a 404 error, but if I add the folders (e.g. localhost:8080/examples)everything displays as it should. It has been a long week already...

9 Years
Discussion Span
Last Post by dickersonka

are you sure that is loading your xml file properly?

for testing purposes try to hardcode it, then move it to the xml file

//continue with the other fields

also, after that if you still get an error, what is it?


well I hardcoded it and now it loads the database, but now my getPost method is crashing. Yeah!


I could still use some help. Now my error seems to be related to the area when I attempt to assign the crs.getMetaData() to a ResultSet. Am I using incompatible types or is it the way I declared RowSetCacheImpl?

protected void doGet( HttpServletRequest request,
      HttpServletResponse response )
         throws ServletException, IOException
      response.setContentType( "text/html" ); 
      PrintWriter out = response.getWriter();

      // start XHTML document
      out.println( "<?xml version = \"1.0\"?>" );

      out.printf( "%s%s%s", "<!DOCTYPE html PUBLIC", 
         " \"-//W3C//DTD XHTML 1.0 Strict//EN\"",
         " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" );

         "<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

      // head section of document
      out.println( "<head>" );  
       	  // get 
        	 out.println( "<title>Thank you!</title>" );
        	 out.println( "</head>" );  
        	 out.println( "<body>" );  
        	 out.println( "<p>Thank you for participating." );
        	 out.println( "<br />Results:</p><pre>" );
        	 // process results
        	 ResultSetMetaData metaData = crs.getMetaData();
        	 int numberOfCol = metaData.getColumnCount();

Still could use help. Here are the tomcat logs as well:

omcat log follows:
Nov 13, 2008 12:03:11 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet faqservlet threw exception
at com.deitel.jhtp6.servlets.FaqListingServlet.doGet(FaqListingServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:613)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.