File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Oracle JDBC coneectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Oracle JDBC coneectivity" Watch "Oracle JDBC coneectivity" New topic

Oracle JDBC coneectivity

Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
I am trying to access Oracle from JSP and my .jsp file is as below, I am getting class not found I missing something? I am using appropriate username,password,host and sid parameters.

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

<Title>Listing The Contents Of a Database Table</Title>
<p>Content of the Employee Table:
<Table Border=1 Cellpadding=0 Cellspacing=0>
<TD> ID </TD>
<TD> Name </TD>
<TD> SSN </TD>

Connection conn = DriverManager.getConnection("jdbc racle:thin:@<host>:<1521>:<sid>","<username>","<password>");
java.sql.Statement statement = conn.createStatement();
java.sql.ResultSet columns = statement.executeQuery("Select * from employee");

while ( {
int ID = columns.getInt("ID");
String Name = columns.getString("Name");
int SSN = columns.getInt("SSN");


<TR> <TD> <%= ID %> </TD>
<TD> <%= Name %> </TD>
<TD> <%= SSN %> </TD>

<% } %>
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
From JSP print the system.getProperty("java.class.path" is see if the classes12.jar or ojdbc.jar is in the classpath. If not add the jar file to the WEB-INF\lib directory.
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
How can I do that? Can you be more specific?
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Miki Nema:
class not found exception

Nothing to do with your code or the connection parameters. The ClassNotFounDException is being produced by the Java classloader because it can't find the driver jar (or zip).

In your case, of course this is the code that triggers it:

The jsp code is correct; your execution environment is wrong. In standalone applications, this is resolved by setting the CLASSPATH environment variable (not to be confused with PATH); in an IDE, it's usually resolved by configuring a classpath within the IDE specific to the project, and (in what is probably your case) within a J2EE application, the jar (or zip) is placed in a standard location for application libraries, commonly [application root]/WEB-INF/lib/

BTW, most experienced J2EE developers seperate their database code from their user interface code, keeping the former in regular java class files and the latter in JSPs (and supporting class files).
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
I have included ojdbc14.jar in my classpath but still getting the same error?
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Just add below line in your jsp where you are making JDBC connection to oracle.

and check the classpath location. Make sure the jar file is in your WEB-INF\lib folder.It's better to test this way rather than including in the classpath. I am not sure if the classpath is same in the webapp server you are using.
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
My classpath location gives this output. But it doesn't show anything like WEB-INF/lib too??//

H:/Sun/AppServer/lib\j2ee-svc.jar;H:/Sun/AppServer/lib \j2ee.jar;H:/Sun/AppServer/lib\jax-qname.jar;
H:/Sun/AppServer/lib\saaj-api.jar;H:/Sun/AppServer/lib\saaj-impl .jar;H:/Sun/AppServer/lib\xalan.jar;H:/Sun/AppServer/lib\xercesImpl.jar;

[edited to add linebreaks so page doesn't scroll right]
[ January 10, 2006: Message edited by: Jeanne Boyarsky ]
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
Thanks to all of you, my programme is working now.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63869

Miki, in the future please do not cross-post the same question in more than one forum.

Forum bartender
[ January 10, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Oracle JDBC coneectivity
It's not a secret anymore!