File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Oracle JDBC connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Oracle JDBC connectivity" Watch "Oracle JDBC connectivity" New topic
Author

Oracle JDBC connectivity

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>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61589
    
  67

Originally posted by Miki Nema:
I am getting class not found exception


Do you not think that it might be useful information to include which class?

If it's the Oracle driver, you need to be sure and include the Oracle jar file containing the driver in a location wheere the web container will pick it up.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
is this class in the classpath?
oracle.jdbc.driver.OracleDriver.


Life called,so here I am.<br />Cheers<br />Niki.:-)
Vikramjit Singh
Greenhorn

Joined: Sep 01, 2005
Posts: 15
I dont know which web server you are using, but if you are using tomcat 5.5.9 then download classes12.zip from oracle site rename it to classes12.jar and place it in tomcatDirectory\common\lib. or follow the instructions from here.

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

thanx.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
All you need a JDBC driver for ORACLE, regardless of any server you are using.
classes12.zip or classes111.zip, it depends on your ORACLE version.
Thanks.
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
I added classes12.jar in my classpath location and I am using java SDK 1.4 server. I also checked the classpath by ,
<%out.println(System.getProperty("java.class.path"));%>
It doesn't show any of the classes like classes12.jar or ojdbc14.jar. Here is the output...

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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61589
    
  67

Originally posted by Miki Nema:
I also checked the classpath by


Servlet containers pay no attention wahtsoever to the system classpath. You need to be sure that the jar file is in one of the locations that the container will examine in order to create its own classpath.
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
so do I need to include that in my pointbase database's direcory?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61589
    
  67

You can include it in the web app's WEB-INF/lib forder, or if you are going to use it in multiple web apps, you can include it in the shareed folder for the container. For Tomcat, that would be $CATALINA_HOME/common/lib.
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
Java SDK doesn't have anything like WEB-INF/Lib folder....do you know whats the directory for SDK server?
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
I included that in web app's web-inf/lib folder and its working now...thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle JDBC connectivity