• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Oracle Connection with JSP

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Using Eclipse and Tomcat I am trying to connect to an Oracle database with a JSP page and keep getting java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver. I have downloaded the OJDBC14.jar for JDK 1.6 and have added it to my classpath. I have run

from cmd and get "ok", so I'm not quite sure where to go from here. If anyone has any suggestions please let me know...

Karl
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classpath is only used during compilation. At runtime the jar file must be placed where Tomcat will load it into its own classpath. If using container-managed connection pooling (highly recommended) place the jar in Tomcat's lib folder.

And please be sure that you are not doing this, or any other Java code, inside a JSP. That is a poor, but all-too-common, practice.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karl,
I saw no mention in your post of the Oracle database version you are using.
I will assume that it is either 10g or 11g.
If you are using java 6, then I suggest you use Oracle's JDBC driver that is recommended for use with java 6 and that is the file "ojdbc6.zip" which can be downloaded from Oracle's Technetwork Web site.
Also, if I remember correctly, class oracle.jdbc.driver.OracleDriver is deprecated (since the release of Oracle's ojdbc14.jar JDBC drive, I believe).

Good Luck,
Avi.
 
karl czukoski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The classpath is only used during compilation. At runtime the jar file must be placed where Tomcat will load it into its own classpath. If using container-managed connection pooling (highly recommended) place the jar in Tomcat's lib folder.

And please be sure that you are not doing this, or any other Java code, inside a JSP. That is a poor, but all-too-common, practice.



Thanks for the direction... what i ended up doing was placing the classes12.jar into the lib directory, and took advantage of the connection pooling concept (http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html) by also placing Jakarta-Commons DBCP 1.0.jar, Jakarta-Commons Collections 2.0.jar, and Jakarta-Commons Pool 1.1.jar into the lib directory. then using eclipse a context.xml file was created under meta-inf with...
...and finally a testpool jsp under web-inf was created and run...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So much for my advice on not writing JSP like it's 2001.
 
karl czukoski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:So much for my advice on not writing JSP like it's 2001.

what do you mean, can you explain what i'm doing wrong?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Repeated from my first reply:

Bear Bibeault wrote:
And please be sure that you are not doing this, or any other Java code, inside a JSP. That is a poor, but all-too-common, practice.

 
karl czukoski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Repeated from my first reply:

Bear Bibeault wrote:
And please be sure that you are not doing this, or any other Java code, inside a JSP. That is a poor, but all-too-common, practice.

How would it be done outside the jsp then, in a servlet? can you provide a more detailed explanation? why isn't java code good inside a jsp?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scriptlets have been discredited for almost 10 years now. Tie to modernize...

Perhaps this article can help.
 
Ranch Hand
Posts: 247
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

karl czukoski wrote:How would it be done outside the jsp then, in a servlet? can you provide a more detailed explanation? why isn't java code good inside a jsp?



Karl, that is a good question. Java code inside a JSP is not good for several reasons:

1. From a Java developer's perspective, it is very tedious and time consuming to embed Java into HTML. For example, creating a table of database results with a Java-HTML mix as with <td> <%= result.getString("ORD_DATE") %> </td> is a lot of trouble and is a little like hardcoding the data display.
2. From a troubleshooter's perspective, Java code in a JSP can look like a complicated mix of HTML, javascript, CSS and Java. If there is a bug somewhere, it will be difficult to find it among the complex code.
3. From a web page designer who only knows HTML and CSS, the Java looks like some mysterious language. It would be difficult to make display format changes in the future.

Your java in JSP is fine for learning purposes but for easier and advanced development the java in JSP could be replaced with a combination of JavaServer Pages Standard Tag Library (JSTL) tags and JavaBeans.

It is also poor, but all-too-common, practice to use servlets to create data output to the web page. In that case, HTML becomes embedded in Java code, which is difficult to read. By the way, of course you do know that JSPs are automatically converted into servlets by Tomcat and those servlets create the display in the client browser. But you, as the programmer, do not need to bother to see or modify that servlet's Java code. Nevertheless, the principle is the same: Java code to produce output should not be mixed by the programmer with non-Java language such as HTML.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic