wood burning stoves 2.0*
The moose likes JDBC 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
Bookmark "Oracle JDBC coneectivity" Watch "Oracle JDBC coneectivity" New topic
Author

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 exception...am I missing something? I am using appropriate username,password,host and sid parameters.


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

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

</TR>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
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 (columns.next()) {
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>

</TR>
<% } %>
</Table>
</Body>
</HTML>
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).
See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassNotFoundException.html

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/jdk/lib/tools.jar;H:/Sun/AppServer/lib/appserv-rt.jar;
H:/Sun/AppServer/lib\activation.jar;H:/Sun/AppServer/lib\admin-cli.jar;
H:/Sun/AppServer/lib\appserv-admin.jar;H:/Sun/AppServer/lib\appserv-cmp.jar;
H:/Sun/AppServer/lib\appserv-ext.jar;H:/Sun/AppServer/lib\appserv-jstl.jar;
H:/Sun/AppServer/lib\appserv-upgrade.jar;
H:/Sun/AppServer/lib\commons-launcher.jar;
H:/Sun/AppServer/lib\commons-logging.jar;H:/Sun/AppServer/lib\dom.jar;
H:/Sun/AppServer/lib\j2ee-svc.jar;H:/Sun/AppServer/lib \j2ee.jar;H:/Sun/AppServer/lib\jax-qname.jar;
H:/Sun/AppServer/lib\jaxr-api.jar;H:/Sun/AppServer/lib\jaxr-impl.jar;
H:/Sun/AppServer/lib\jaxrpc-api.jar;H:/Sun/AppServer/lib\jaxrpc-impl.jar;
H:/Sun/AppServer/lib\jmxremote.jar;
H:/Sun/AppServer/lib\jmxremote_optional.jar;H:/Sun/AppServer/lib\jsf-api.jar
;H:/Sun/AppServer/lib\jsf-impl.jar;H:/Sun/AppServer/lib\mail.jar;
H:/Sun/AppServer/lib\relaxngDatatype.jar;H:/Sun/AppServer/lib\rmissl.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;
H:/Sun/AppServer/lib\xsdlib.jar;
H:/Sun/AppServer/lib/install/applications/jmsra/imqjmsra.jar;
H:/Sun/AppServer/imq/lib/jaxm-api.jar;H:/Sun/AppServer/imq/lib/fscontext.jar
;H:/Sun/AppServer/lib/ant/lib/ant.jar;
H:/Sun/AppServer/pointbase/lib/pbclient.jar;
H:/Sun/AppServer/pointbase/lib/pbembedded.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
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

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

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle JDBC coneectivity