Dear all, No matter what I do, I can't seem to be able to make the JSP with Database work. How can I connect to an Oracle database which is hosted in our University, over a JSP page.

I have a project where we need to connect to Oracle database using a JSP web page. We have to add, delete and update tables created by us on the oracle database and then show them on a webpage. I have installed Tomcat and it is running fine under localhost:80.

I can test and run JSP pages fine on my laptop however when it comes to Database, I can't seem to get it working.

Here is the Code I am using

<%@ taglib  prefix="c"   uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib  prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"   %>

<sql:setDataSource    
					var = "db"
                   driver = "oracle.jdbc.driver.OracleDriver"
                      url = "jdbc:oracle:thin:@oracle.<uni-name>:1522:ugdb11"
                     user = "USERNAME"
                 password = "PASSWORD"/> 

<sql:query var="allBooks" dataSource="${db}"> 
     select * from books
</sql:query>          

<html>
 <head> 
   <title> All books </title>
 </head>
 <body>
  <h1> All Books </h1>
 
   <ol>
 
      <c:forEach var="row" items="${allBooks.rows}">
          
                <li>  ${row.isbn}    ....
                      ${row.title}   
                </li>                  
         
          
      </c:forEach>

   </ol>

   <p> End of listing. </p>
 </body>
</html>

When I run the above JSP page I get the following error:

HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /cheapBooks.jsp at line 4

1: <%@ taglib  prefix="c"   uri="http://java.sun.com/jsp/jstl/core"  %>
2: <%@ taglib  prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"   %>
3: 
4: <sql:setDataSource    
5: 					var = "db"
6:                    driver = "oracle.jdbc.driver.OracleDriver"
7:                       url = "jdbc:oracle:thin:@oracle.<uni-name>:1522:ugdb11"


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspTagException: In &lt;driver&gt;, invalid driver class name: "java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver"
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:851)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
	org.apache.jsp.cheapBooks_jsp._jspService(cheapBooks_jsp.java:98)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
	java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
	java.lang.Class.forName0(Native Method)
	java.lang.Class.forName(Class.java:247)
	org.apache.taglibs.standard.tag.common.sql.DataSourceWrapper.setDriverClassName(DataSourceWrapper.java:46)
	org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport.doStartTag(SetDataSourceTagSupport.java:102)
	org.apache.jsp.cheapBooks_jsp._jspx_meth_sql_005fsetDataSource_005f0(cheapBooks_jsp.java:123)
	org.apache.jsp.cheapBooks_jsp._jspService(cheapBooks_jsp.java:66)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Please help!. I am stuck and don't know what to do.

Regards

Jehanzeb

From the stacktrace the exception is
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
meaning that the jar file containing the jdbc drivers is not available.

Try placing the jdbc driver jar file
e.g. classes12.jar for Oracle 10g
in the folder <tomcat_home>\common\lib
and restarting tomcat

It does not seems to be a d/b server location issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.