aspose file tools*
The moose likes JSP and the fly likes Oracle Connection with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Oracle Connection with JSP" Watch "Oracle Connection with JSP" New topic
Author

Oracle Connection with JSP

karl czukoski
Greenhorn

Joined: Dec 30, 2010
Posts: 22
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

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

Joined: Dec 30, 2010
Posts: 22
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

So much for my advice on not writing JSP like it's 2001.
karl czukoski
Greenhorn

Joined: Dec 30, 2010
Posts: 22
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

Joined: Dec 30, 2010
Posts: 22
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Scriptlets have been discredited for almost 10 years now. Tie to modernize...

Perhaps this article can help.
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
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.


SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle Connection with JSP
 
Similar Threads
jsp page not show oracle data
Probelm using XSU
PROBLEMS IN CONNECTING TO ORACLE
Problem with conn to oracle
about class not found exception in eclipse