I'm having very similar problems, using Oracle 7.3.4 on win98.
Also noted you need to start the oracle listeners to get a connection on
port 1521.
My program and key parameters are detailed in the attached two files, I
included some reference points since there are a few things to check in
the oracle configuration etc.
One thing I am not sure of is how to check the .dll files included in the
oracle driver distribution for windows are being found by the driver
package.
Also does anyone know how to setup ODBC:JDBC connection to Oracle? It
might turn out to be easier to get that working instead... (tho loess
preferable)
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import oracle.*;//this line inserted resolve classpath problem.
//import oracle.jdbc.driver.OracleDriver;
/*
Create new project.
*/
public class ConnectOraclewithclasses111 extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("setting up variables in ConnectOraclewithclasses111 using oci7 driver, Tues 11-Jul, 33<BR>");
// define query string.
String sql1 = "select * from dual";
try
{ //open data base connection.
out.flush();
out.println("registering driver for connection to database.<BR>");
Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
out.println("class registered, getting connection.<BR>");
Connection m_connection = DriverManager.getConnection
("jdbc:oracle:oci7:@SID1","scott", "tiger");
// ("jdbc:oracle:thin:@ORCL","scott", "tiger");
// ("jdbc:oracle:oci7:@ORCL","scott", "tiger");
out.println("Connection to database succeeded.<BR>");
Statement stmt = m_connection.createStatement();
out.println("stmt created.<P>");
stmt = m_connection.createStatement();
try
{ // try Z2, run query to check if userid & password are valid.
out.println("executing sql1 ="+sql1+"<BR>");
ResultSet rs = stmt.executeQuery(sql1);
out.println("sql executed.<BR>");
if (rs.next()) // if Z3-ValidUser
{
out.println("non null set returned by query.<BR>");
}//
else
{
out.println("Invalid userID or Password, please try again.");
}
}//
catch(Exception ex){ //Trap SQL errors
out.println("Error selecting on userid.<BR>"+ex.toString()+"<br>" + System.getProperties());} // end try Z2
stmt.close();
m_connection.close();
} // first try catching classnot found error.
// catch(ClassNotFoundException ex){ //
// out.println("Error loading driver class. Exception information<BR>"+ex.toString()+
// "<br><br>System information.<br>" + System.getProperties());
// }// catch all other errors.
catch(Exception ex){ //
out.println("Error connecting to database. Exception information<BR>"+ex.toString()+
"<br><br>System information.<br>" + System.getProperties());
}//
out.println("</body></html>");
} // end doGet
}
I'm pretty sure this is a java classpath type problem, but have run out of ideas.
I have been playing with apache/java servlets using jdbc connections to Oracle. At uni I had it working on Oracle8/Sun OS, also have a working installation on Oracle8/Redhat6.1 .
At the moment I am trying to get a similar configuration workin on a windows platform. I am using the following packages.
Personal Oracle7 Release 7.3.4.0.0 - Production Release
Apache/1.3.12 (win32) Apache Jserv/1.1.2
jdk1.1.8
I have tested the Apache/Jserv configuration (IsItWorking loads no problem), even had jdbc/odbc connections working communicating with MSaccess.
I am getting
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
I am using the classes111.zip driver for windows. (NB it is written for jdk1.1.1, I'm using jdk1.1.8 is that an issue?)
my java classpath is
c:\myweb\jdk1.1.8\lib\classes.zip; #standard part of jdk library
C:\myweb\jsdk2.0\lib\jsdk.jar; #required for Jserv
C:\myweb\data\classes111.zip #required for jdbc bridge to Oracle.
The dll files OCI73JDBC.DLL and oci73jdbc_g.dll (not sure if the 2nd dll is required) have been manually copied across to c:\orawin95\bin directory. I also tried using only one of the dll's at a time, I havent found anything that says anything other than the dll's should be placed in the windows path.
using winzip to view the contents of classes111.zip shows that oracle\jdbc\driver\OracleDriver.class exists within the classes111.zip file.
The Oracle jdbc howto I looked at suggested using the lines below.
import java.sql.*;
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:oci7:@mydatabase","scott", tiger");
The full java file is attached below.
the Servlet runtime error message is here, a couple of things that dont make sense to me
- classpath as printed in the error message thrown does not show classes111.zip even though it shows when compiling.
setting up variables in ConnectOraclewithclasses111 using oci7 driver, Tues 11-Jul, 33
registering driver for connection to database.
Error connecting to database. Exception information
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
System information.
{user.language=en, java.home=C:\MYWEB\JDK1.1.8\BIN\.., java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, awt.toolkit=sun.awt.windows.WToolkit, file.encoding.pkg=sun.io, java.version=1.1.8, file.separator=\, line.separator= , user.region=US, file.encoding=Cp1252, java.compiler=symcjit, java.vendor=Sun Microsystems Inc., user.timezone=AET, user.name=mat, os.arch=x86, os.name=Windows 95, java.vendor.url=http://www.sun.com/, user.dir=C:\WINDOWS\Profiles\mat\Desktop, java.class.path=c:\myweb\jserv\ApacheJServ.jar;c:\myweb\jsdk2.0\lib\jsdk.jar;C:\MYWEB\JDK1.1.8\BIN\..\classes;C:\MYWEB\JDK1.1.8\BIN\..\lib\classes.zip;C:\MYWEB\JDK1.1.8\BIN\..\lib\classes.jar;C:\MYWEB\JDK1.1.8\BIN\..\lib\rt.jar;C:\MYWEB\JDK1.1.8\BIN\..\lib\i18n.jar, java.class.version=45.3, os.version=4.10, path.separator=;, user.home=C:\MYWEB\JDK1.1.8\BIN\..}
The java classpath shown when compiling is shown below from the kawa compile message below.
c:\myweb\jdk1.1.8\bin\javac.exe ConnectOraclewithclasses111.java
Class Path - .;C:\Program Files\Kawa\classes.zip;c:\myweb\jdk1.1.8\lib\classes.zip;C:\myweb\jsdk2.0\lib\jsdk.jar;C:\myweb\data\classes111.zip
File Compiled...
No Errors...
the classpath as defined in kawa > packages > classpath is
C:\myweb\jsdk2.0\lib\jsdk.jar;C:\myweb\data\classes111.zip;
What I dont understand is how/why the code doesnt need an "import oracle.*;" line in the java code since servlets need the jsdk.jar file in the classpath and
import javax.servlet.*;
import javax.servlet.http.*;
to load the servlet drivers.
I looked at tnsnames.ora to find the "SID" for my system, chose ORCL. left the password as scott/tiger.
Any ideas??
I have attached below screendumps and the key configuration files from the major packages, maybe there is something obvious there.
This is screendump from starting Oracle windows client.
SQL*Plus: Release 3.3.4.0.0 - Production on Fri Jul 07 10:54:41 2000
Copyright (c) Oracle Corporation 1979, 1996. All rights reserved.
Connected to:
Personal Oracle7 Release 7.3.4.0.0 - Production Release
With the distributed and replication options
PL/SQL Release 2.3.4.0.0 - Production
this is screendump from starting oracle listener,
LSNRCTL for 32-bit Windows: Version 2.3.4.0.0 - Production on 07-JUL-00 10:54:19
Copyright (c) Oracle Corporation 1994. All rights reserved.
Starting tnslsnr: please wait...
TNSLSNR for 32-bit Windows: Version 2.3.4.0.0 - Production
System parameter file is C:\ORAWIN95\network\admin\listener.ora
Log messages written to C:\ORAWIN95\network\log\listener.log
Listening on: (ADDRESS=(PROTOCOL=tcp)(DEV=124)(HOST=127.0.0.1)(PORT=1521))
Connecting to (ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 2.3.4.0.0 - Production
Start Date 07-JUL-00 10:54:23
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security OFF
SNMP OFF
Listener Parameter File C:\ORAWIN95\network\admin\listener.ora
Listener Log File C:\ORAWIN95\network\log\listener.log
Services Summary...
ORCL has 1 service handler(s)
The command completed successfully
the tnsnames.ora file is below for reference.
#This is a SQL*Net Configuration file generated by SQL*Net Easy Configuration.
#Attention: Do not modify this file yourself.
#If you do, your SQL*Net Easy Configuration may not function properly.
Example1.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = Production1)
(Port = 1521)
)
)
(CONNECT_DATA = (SID = SID1)
)
)
Example2.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = spx.world)
(PROTOCOL = SPX)
(Service = Server_lsnr)
)
)
(CONNECT_DATA = (SID = ORCL)
)
)
Example3.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = nmp.world)
(PROTOCOL = NMP)
(Server = FinanceServer1)
(Pipe = ORAPIPE)
)
)
(CONNECT_DATA = (SID = ORCL)
)
)
Tcp-loopback.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = 127.0.0.1)
(Port = 1521)
)
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = 127.0.0.1)
(Port =
...
read more »