• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

could not find database driver - jsp

Hi,

im receiving an error saying

Could not find the database driver

and then hence

Could not connect to the database

i have classes111.zip in WEB-INF/lib of tomcat folder

Anyone any ideas?
0
act1ve
Asked:
act1ve
  • 20
  • 16
  • 8
2 Solutions
 
bloodredsunCommented:
you need to unzip the classes111.zip file into that folder
0
 
bloodredsunCommented:
you should put the jar files into WEN-INF/lib and any .class files into WEB-INF/classses. If there is a web.xml file, it goes in WEB-INF.
0
 
bloodredsunCommented:
See here for an example of the basic structure of a webapp http://e-docs.bea.com/wls/docs70/webapp/basics.html
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
act1veAuthor Commented:
thanks,

i unzipped and it created 2 directories, javax and oracle with numerous sub directories in the oracle one.

Still receiving the same error though. Do i have to seperate all the files inside these directories? There are quite a number. If so do i break the directory structure?
0
 
bloodredsunCommented:
what are these files? Are they jars or are they class files? Javax is a reserved keyword for Suns exterprise library (j2ee.jar and servlet.jar for example). To picked up by tomcat the jars must be directly in the WEB-INF/lib folder

Where did you download this zip from, are there no installation instructions?
0
 
act1veAuthor Commented:
the file classes111.zip was located in C:\oracle\ora81\jdbc\lib\classes111.zip. The oracle client software was already installed on my machine and is apparently all i need for conneciton to the database.

in javax there is another folder called sql which holds many class files (ConnecitonEvent.class for example). The oracle folder has numerous other folders all containing classes
0
 
bloodredsunCommented:
All class files belong in directories in the folder WEB-INF/classes depending on their package. If I have a class called DBConnector that is in the package com.bloodredsun.dbUtils (as declared at the top of the source code) then it would need to go into the folder WEB-INF/classes/com/bloodredsun/dbUtils.

Also, have you downloaded the Oracle driver and palced that Jar in the WEB-INF/lib folder?

But again, where did you download this zip from, are there no installation instructions?

Can you please show the exception/error you are getting, and maybe the relevent bitof the jsp you are using?
0
 
bloodredsunCommented:
All class files belong in directories in the folder WEB-INF/classes depending on their package. If I have a class called DBConnector that is in the package com.bloodredsun.dbUtils (as declared at the top of the source code) then it would need to go into the folder WEB-INF/classes/com/bloodredsun/dbUtils.

Also, have you downloaded the Oracle driver and palced that Jar in the WEB-INF/lib folder?

But again, where did you download this zip from, are there no installation instructions?

Can you please show the exception/error you are getting, and maybe the relevent bitof the jsp you are using?
0
 
TimYatesCommented:
>>  you need to unzip the classes111.zip file into that folder

!  I don't think you do...

You need to do

     Class.forName( "oracle.jdbc.OracleDriver" ) ;

Before you try to get a connection from the DriverManager...

it should be fine as it was.  As a zip file in the WEB-INF/lib

Actually...are you defining a resource in server.xml?

In that case, you need to move classes111.zip into tomcat/common/lib
0
 
act1veAuthor Commented:
This zip is the same as which can be downloaded from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc817.html

That creates the directories javax and oracle when unzipped? It doesnt seem to come just as one jar file?

The error i get is:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:71: ';' expected.
                        Could not find the database driver
                                 ^


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:73: ';' expected.
                        Could not connect to the database

Thanks for all your help
0
 
bloodredsunCommented:
You mean like this?
http://www.mathworks.com/access/helpdesk/help/toolbox/database/instal13.html

It might work if you just rename it from .zip to .jar
0
 
TimYatesCommented:
>> It might work if you just rename it from .zip to .jar

It will work as .zip

Or at least I always used it as .zip
0
 
TimYatesCommented:
Ahhhh...  Tomcat might not automatically add it to the classpath...

try renaming it to .jar as brs said ;-)

I'll be quiet now ;-)
0
 
bloodredsunCommented:
>>I'll be quiet now ;-)

Don't! you always seem to stop me from barking up the wrong tree %-)
0
 
act1veAuthor Commented:
i renamed the zip file to .jar but still the same error posted earlier appears.

This is my code for connection:

<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "myhost";
        String portNumber = "1521";
        String sid = "MACH";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "myusername";
        String password = "mypassword";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        Could not find the database driver
    } catch (SQLException e) {
        Could not connect to the database
    }

%>

Does that seem ok?
0
 
TimYatesCommented:
>> Don't! you always seem to stop me from barking up the wrong tree %-)

Hehehe, same here :-D

act1ve, you are doing:

    Class.forName( "oracle.jdbc.OracleDriver" ) ;

before you try to get your connection aren't you?
0
 
TimYatesCommented:
Try

        String driverName = "oracle.jdbc.OracleDriver";

(NB:  I may be wrong, but I seem to remember that's what it was called)

I always used to use classes12.zip tho, not 111
0
 
act1veAuthor Commented:
sorry mate, not too sure what you mean there, do you mean in that jsp connection which i just posted?

       String driverName = "oracle.jdbc.driver.OracleDriver";
       Class.forName(driverName);

?

If so i assumed drivername was declared as a string and used then by Class.forName?
0
 
act1veAuthor Commented:
tried removing driver but the same prob, im stuck using classes111 because of jdkv1 only being installed on this computer :(

thanks for all your continued help
0
 
TimYatesCommented:
Yeah, that's cool...but try:

String driverName = "oracle.jdbc.OracleDriver";

instead of

String driverName = "oracle.jdbc.driver.OracleDriver";
0
 
act1veAuthor Commented:
again same error :( not looking good :/
0
 
TimYatesCommented:
>>  tried removing driver but the same prob

Ahhh...

I know what it is!! :-D  *bounce*

Change this:

     String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;

to this:

     String url = "jdbc:oracle:thin:@//" + serverName + ":" + portNumber + "/" + sid;

You had the OCI format...tht's now the thin format :-)

Tim
0
 
TimYatesCommented:
hehehe...hope that's right or else I'm gonna look dumb ;-)
0
 
TimYatesCommented:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#05_01

is where I found the 2 different connect string formats :-)
0
 
act1veAuthor Commented:
hehe you sound really confident so i reckon you could be correct with that,

however im still getting those same damn errors so im guessing it must be my setup here rather than your improved conneciton script

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:71: ';' expected.
                        Could not find the database driver

You kn how it says generated servlet error in d:\

I am running tomcat off of g:\ however.

Coud this be making any difference?
0
 
TimYatesCommented:
Is there a Tomcat install in D:?

That's a bit odd...

And it does sound like you have a ";" missing...

are you sure you don't have 2 tomcat installs?
0
 
act1veAuthor Commented:
yes there is a tomcat install in d also,

the problem is the way this computer is setup. a tomcat install was originally on d and then i installed on g which is a drive i have full access to. i only have read access to d unfortunaetly.

i am running tomcat off g: though so i start it with the startup batch file from g:

Im guessing it should run from g: then, i can navigate to http://localhost:8080 and see the install page, and also /momentum which is a folder i have created on the tomcat install on g: with all my jsp files.

Im guessing this is causing conflict though? although the tomcat install on d is not running?
0
 
TimYatesCommented:
>> although the tomcat install on d is not running?

Are you sure? ;-)  Is it running as a service?

Ok, that sounds like catalina.home or something is going back to the D value :-/

Odd...

Can you post the entire JSP that's causing the error?  Is it HUGE?  Hmmm...

I take it that the lines:

        Could not find the database driver

and

        Could not connect to the database

are REALLY something like:

        out.println( "Could not connect to the database" ) ;

yes?

Tim
0
 
act1veAuthor Commented:
yea its not running :)

enitre jsp isnt big at all, i have a simple query.jsp which is:

<%@ include file="db.jsp"%>

<%

 try {
        // Create a result set containing all data from my_table
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM Supervisor");
    } catch (SQLException e) {
    }


%>

and then the db.jsp as posted earlier:

<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "ora.wit.ie";
        String portNumber = "1521";
        String sid = "MACH";
        String url = "jdbc:oracle:thin:@//" + serverName + ":" + portNumber + "/" + sid;
        String username = "W01606662";
        String password = "EGPZAR";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver");
    } catch (SQLException e) {
        out.println( "Could not connect to the database");
    }

%>
0
 
TimYatesCommented:
what happens if you just go to db.jsp?

does that work?

Oh, and I'd probably change your username/password on the database after this is solved :-/

And can you post the actual exception?
0
 
act1veAuthor Commented:
hehe yea i noticed that i posted those details! silly me! :)

db.jsp bring up exact same as query.jsp


exception:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\db$jsp.java:71: ';' expected.
                        Could not find the database driver
                                 ^


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\db$jsp.java:73: ';' expected.
                        Could not connect to the database
                                 ^
2 errors, 1 warning

      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285)
      at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
      at java.lang.Thread.run(Thread.java:536)

doesnt jsp give horrible errors :)
0
 
TimYatesCommented:
right...

the db.jsp that it's executing doesn't have

        out.println( "Could not find the database driver");

but just has

        Could not find the database driver


like in the example you posted earlier...

That's what I reckon the problem is now...

>> doesnt jsp give horrible errors :)

Oh yes!  At least this one's useful...  there's the 1% of errors where it says "null"

Thanks Tomcat ;-)

hehehe

Tim
0
 
act1veAuthor Commented:
hmm yea i changed the file to suit with your out.print included but it is still returning the same error.

your right though it is obviously looking for ; at the end of those 2 lines.

i have restarted tomcat for it to take effect but nothing. db.jsp has definatly been changed though to what you suggested.

its just a case of saving these files as .jsp yes?

unlike .java then dont need compiling or anything?
0
 
TimYatesCommented:
yeah..that should work (tomcat should pick up the changes and recompile them)

Are you sure you only have one "db.jsp" file?  You could be changing one, and tomcat could be using the other...

Happened to me a few times...and it really makes your brain itch ;-)
0
 
TimYatesCommented:
If you're sure, then try stopping tomcat, and removing anything inside Tomcat/work

then restart...that should kick tomcat into action ;-)
0
 
act1veAuthor Commented:
ah Tim, i was editing another db file which wasnt in momenutm, something simple eh?

i'm not getting:

An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:56: Class org.apache.jsp.Connection not found.
                    Connection connection = null;
                    ^


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:69: Undefined variable or class name: DriverManager
                        connection = DriverManager.getConnection(url, username, password);
                                     ^


An error occurred between lines: 1 and 23 in the jsp file: /momentum/db.jsp

Generated servlet error:
D:\Tomcat4\work\Standalone\localhost\_\momentum\query$jsp.java:72: Class org.apache.jsp.SQLException not found.
                    } catch (SQLException e) {
                             ^

I'm puzzled :/
0
 
TimYatesCommented:
Right, you need to import java.sql.* into both your JSPs :-)

Put:

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

at the top of both your JSPs :-)
0
 
act1veAuthor Commented:
this is what i get now:

java.lang.NullPointerException
      at org.apache.jsp.query$jsp._jspService(query$jsp.java:100)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
      at java.lang.Thread.run(Thread.java:536)


hehe bit of a long error there, at least you got rid of any errors in my code :)
0
 
TimYatesCommented:
Right...that's the sort of useless exception I'm talking about ;-)

hehehehe

Change "query.jsp" to:

<%@ page import="java.sql.*" %>
<%@ include file="db.jsp"%>
<%
 if( connection == null )
 {
    out.println( "Giving up...connection is null" ) ;
 }
 else
 {
    try {
        // Create a result set containing all data from my_table
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM Supervisor");
       } catch (SQLException e) {
       }
 }
%>
0
 
TimYatesCommented:
>> at least you got rid of any errors in my code :)

I think we're just back to it failing to get a connection again ;-)

hehehe...  3 steps forward, and errr...  3 back to the start ;-)

Try that change, and see what it says...at least we will then have working code (even if it still fails)

Tim
0
 
act1veAuthor Commented:
hehe yea i see what ya mean, you had to change it to show what error it might be, good thinking

yes it came up with: Could not connect to the database Giving up...connection is null

Something wrong with the actualy connection to my database so is there?
0
 
TimYatesCommented:
Try changing:

    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver");
    } catch (SQLException e) {
        out.println( "Could not connect to the database");
    }

to:

    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver: " + e.getMessage() );
    } catch (SQLException e) {
        out.println( "Could not connect to the database: " + e.getMessage() );
    }

and see if that give a bit more info :-)
0
 
act1veAuthor Commented:
hey Tim i finally got it all working!!! :)

i decide to change the query file and put db.jsp in it itself without the use of include.

Also i tried a different conneciton string String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;

it connects to the database ok and i did:

while( rs.next() )
      {
            out.println( rs.getString( 1 ) + "<BR>" );
      }

to print out the values form the query!

Without all you help i wouldnt be able to do it, your a hero!
0
 
TimYatesCommented:
>>  hey Tim i finally got it all working!!! :)

Yay!!!

>> String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;

Ahhhh...so I was wrong, your original connect string was right :-)  hehehe...  My *bounce* was premature ;-)

>> Without all you help i wouldnt be able to do it, your a hero!

Hehe, no worries!  I'm glad we got it sorted out :-)

It's great when it all works ;-)

Good luck with it all!

Tim
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 20
  • 16
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now