Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:33:24+00:00 2026-06-03T01:33:24+00:00

I have inserted the following java code in the body part of my jsp

  • 0

I have inserted the following java code in the body part of my jsp page to retrieve the records of the table FLIGHTDATA from a Oracle 10g database. But after the execution of the Class.forName(…) line the program directly goes to finally block and closing the connection without returning any data. Any suggestions on what I am doing wrong ? Thanks – Somnath

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<%
out.println("<table border='1'><tr>");
Connection connection = null;
Statement statement = null;
ResultSet rs_1hop = null;
ResultSetMetaData rsm_1hop = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionURL = "jdbc:oracle:thin:@localhost:1521:xe";
connection = DriverManager.getConnection(connectionURL, "system", "system");
statement = connection.createStatement();
// sql query to retrieve values from the secified table.
String QueryString = "SELECT * from FLIGHTDATA";
rs_1hop = statement.executeQuery(QueryString);
rsm_1hop = rs_1hop.getMetaData();
int colCnt = rsm_1hop.getColumnCount();

for (int i=1; i<=colCnt; ++i) {
    out.println("<th>" + rsm_1hop.getColumnName(i) + "</th>");
}
out.println("</tr>");

while (rs_1hop.next()) {
    out.println("<tr>");
    for (int i=1; i<=colCnt; ++i)
        out.println("<td>" + rs_1hop.getString(i) + "</td>");
    out.println("</tr>");
}

} catch (Exception e) {

} finally {
    if (statement != null)
        statement.close();
    if (connection != null)
        connection.close();
}
out.println("</table><br><br>");
%>

After adding the ServletException in the catch block as commented by BalusC, and adding the odbc6.jar files under /WEB-INF/lib, I am getting the following error message which I suppose is due to the jdbc driver not found.

I also tried adding the jar files under Apache Tomcat installation dir /ROOT/web-apps/WEB_INF/lib so that they are available for all web-apps but the problem persists.

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: DB interaction failed!           org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: DB interaction failed!
     org.apache.jsp.retrievePossibleRoutes_jsp._jspService(retrievePossibleRoutes_jsp.java:96)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Unknown Source)
    org.apache.jsp.retrievePossibleRoutes_jsp._jspService(retrievePossibleRoutes_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:33:25+00:00Added an answer on June 3, 2026 at 1:33 am

    But after the execution of the Class.forName(…) line the program directly goes to finally block

    That can only happen if a ClassNotFoundException was been thrown. This means that concrete class as specified by the given class name is not in the webapp’s runtime classpath at all. That class is part of the Oracle JDBC driver. Putting the Oracle JDBC driver JAR file in /WEB-INF/lib folder of the webapp should fix that problem.

    Further I strongly recommend you to do something in that empty catch (Exception e) {} block to indicate that an exception has occurred. Right now you’re stabbing clueless around in the dark as to what really happened. If you have rethrown it as a ServletException, then you’d have gotten a much more self-explaining error page instead of a halfbaked JSP result.

    } catch (Exception e) {
        throw new ServletException(e);    
    }
    

    Last but not least, writing Java code in a JSP file is a bad practice. How to salvage this properly, check this answer: Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern.


    Update as per your update:

    After adding the ServletException in the catch block as commented by BalusC, and adding the odbc6.jar files under /WEB-INF/lib, I am getting the following error message which I suppose is due to the jdbc driver not found.

    Then it’s the wrong JAR file (i.e. it’s not the one containing the oracle.jdbc.driver.OracleDriver class), or you didn’t rebuild/redeploy/restart the webapp properly. Make sure that you’ve downloaded the right JDBC driver for your Oracle database version as listed here. Make sure that you’ve properly rebuilt/redeployed/restarted the webapp.


    I also tried adding the jar files under Apache Tomcat installation dir /ROOT/web-apps/WEB_INF/lib so that they are available for all web-apps but the problem persists.

    This is nonsense. Undo this change. To make a JAR available to all deployed webapps, put it in Tomcat’s own /lib folder (the one straight in Tomcat installation folder). But that won’t solve your problem if it’s the wrong JAR file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code for inserting video bytes into the database DBAdapter.java
I have inserted the following asm code in my C++ code. I am using
Lets say i have the following bit of code import java.sql.Connection; import java.sql.DriverManager; import
I have the following table I have inserted Product B to it and it
I have inserted the following line into my Joomla template: <jdoc:include type=component /> This
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
I have inserted a code to display product attribute in view.phptml, which works fine.
I have a iframe on my page. I have inserted a background image on
I'm trying to select an element from my webpage... I have inserted a control
I have created an sqlite table using the following statement: CREATE TABLE IF NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.