connecting to Oracle ( on a UNIX server) from my PC with JDBC
791392Dec 3 2003 — edited Dec 7 2003hi
i am trying to run a sample program, employee.java, from my PC. I want to connect to an Oracle Database residing on a UNIX server, using JDBC.
The code is as follows:
-----------------------------------------------------------------
class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ect-sun.ecst.csuchico.edu)(PORT=1521)))(CONNECT_DATA=(SID=ecstDB)(SERVER=DEDICATED)))","elango","passwd");
// thanks to Daniels for getting this to work!
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from all_users");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
--------------------------------------------------
and when i run this program at the command prompt in my Windows PC., this is what I get..
C:\j2sdk1.4.2_02\bin>java Employee
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.driver.
OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Employee.main(Employee.java:17)
-----------------------------
could anybody help me out?
thanks in advance