Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle JDBC connectivity

 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this class in the classpath?
oracle.jdbc.driver.OracleDriver.
 
Vikramjit Singh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so do I need to include that in my pointbase database's direcory?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java SDK doesn't have anything like WEB-INF/Lib folder....do you know whats the directory for SDK server?
 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I included that in web app's web-inf/lib folder and its working now...thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic