Hi, Add debugging statements to assert that the connection is not null, the statement is created OK, etc, rather than just one exception around everything.
Yoav Shapira Millennium Research Informatics >-----Original Message----- >From: Vassilis Atlamazoglou [mailto:[EMAIL PROTECTED] >Sent: Tuesday, August 03, 2004 6:08 AM >To: Tomcat Users List >Subject: accessing a database via Tomcat > >I have a database in MS Access which has a system DSN (and a user DSN) in >ODBC Data Source Administrator of Windows XP. I can access the data with > > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > Connection c = DriverManager.getConnection("jdbc:odbc:odbc_exmp"); > >with a simple executable java file. But I cannot have access with the >following servlet > >import java.sql.*; >import java.io.*; >import javax.servlet.*; >import javax.servlet.http.*; > >public class DisplayServlet extends HttpServlet { > > public void doGet(HttpServletRequest req, HttpServletResponse res) > throws ServletException, IOException { > > res.setContentType("text/html"); > PrintWriter out = res.getWriter(); > > out.print ("<HTML><HEAD><TITLE>Display Records"); > out.print ("</TITLE></HEAD><BODY>"); > out.println("<H1>Display Records</H1>"); > > > res.setContentType("text/html"); > > > // debugging info > > long time1 = System.currentTimeMillis(); > > // connecting to database > > Connection con = null; > Statement stmt = null; > ResultSet rs = null; > String userID = ""; > String passwd = ""; > String dbURL = "jdbc:odbc:odbc_exmp"; > try { > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > con = DriverManager.getConnection(dbURL, userID, passwd); > > stmt = con.createStatement(); > rs = stmt.executeQuery("SELECT * FROM Names"); > > // displaying records > > while(rs.next()) { > out.print(rs.getObject(1).toString()); > out.print("\t"); > out.print(rs.getObject(2).toString()); > out.print("\t\t"); > out.print(rs.getObject(3).toString()); > out.print("\n"); > } > > > } catch (SQLException e) { > throw new > ServletException("Servlet Could not display records.", e); > } catch (ClassNotFoundException e) { > throw new > ServletException("JDBC Driver not found.", e); > } finally { > try { > if(rs != null) { > rs.close(); > rs = null; > } > if(stmt != null) { > stmt.close(); > stmt = null; > } > if(con != null) { > con.close(); > con = null; > } > } catch (SQLException e) {} > } > > // debugging info > > out.println ("</BODY></HTML>"); > > > } >} > >via Tomcat 4.1 > >with the following error messages: > >type Exception report > >message > >description The server encountered an internal error () that prevented it >from fulfilling this request. > >exception > >javax.servlet.ServletException: Servlet Could not display records. > at DisplayServlet.doGet(DisplayServlet.java:55) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > at >org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet .jav >a >:466) > at >org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:1 80) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > at >org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic atio >n >FilterChain.java:247) > at >org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil terC >h >ain.java:193) > at >org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal ve.j >a >va:256) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardContextValve.invoke(StandardContextVal ve.j >a >va:191) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardContext.invoke(StandardContext.java:24 22) > at >org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jav a:18 >0 >) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherV alve >. >java:171) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:641) > at >org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav a:16 >3 >) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:641) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve .jav >a >:174) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) > at >org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:8 28) > at >org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process Conn >e >ction(Http11Protocol.java:700) > at >org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:5 84) > at >org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPoo l.ja >v >a:683) > at java.lang.Thread.run(Thread.java:534) > >root cause > >java.sql.SQLException: General error > at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6987) > at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115) > at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074) > at >sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323 ) > at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174) > at java.sql.DriverManager.getConnection(DriverManager.java:512) > at java.sql.DriverManager.getConnection(DriverManager.java:171) > at DisplayServlet.doGet(DisplayServlet.java:37) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > at >org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet .jav >a >:466) > at >org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:1 80) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > at >org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic atio >n >FilterChain.java:247) > at >org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil terC >h >ain.java:193) > at >org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal ve.j >a >va:256) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardContextValve.invoke(StandardContextVal ve.j >a >va:191) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardContext.invoke(StandardContext.java:24 22) > at >org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jav a:18 >0 >) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherV alve >. >java:171) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:641) > at >org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav a:16 >3 >) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:641) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve .jav >a >:174) > at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invo >k >eNext(StandardPipeline.java:643) > at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 480) > at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > at >org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) > at >org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:8 28) > at >org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process Conn >e >ction(Http11Protocol.java:700) > at >org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:5 84) > at >org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPoo l.ja >v >a:683) > at java.lang.Thread.run(Thread.java:534) >Can anybody help me? What should I check in order to have access to my >database through Tomcat.Thank you in advance Vassilis > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
