Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with JDBC Connection to oracle

9 views
Skip to first unread message

michael thomas

unread,
Mar 2, 2001, 5:28:38 PM3/2/01
to
Hi, I am at the early stages of setting up a connection to Oracle via JDBC,
so the following code is not yet complete, but I thought that I would
compile it and run it in stages. Anyways, it does compile but when I run it
I get an error. Note that I have not downloaded any of the drivers from
Oracle. Why have have I not downloaded any of the drivers? because I
understand from the documentation that they come as part of the jdk1.3
install. Please correct me if I wrong on this assumption. This may be the
problem but I am unsure where to get the drivers and in what form?

Thanks in advance everyone!

CLASSPATH:
**************
=.;D:\jdk1.3\lib

ERROR:
********
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at jdbc_example.main(jdbc_example.java:12)

Process completed successfully


CODE:
*******
import java.sql.*;
class jdbc_example
{
public static
void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (Exception ex)
{
ex.printStackTrace();
}

}
}


mbhadury

unread,
Mar 3, 2001, 10:56:10 AM3/3/01
to
Hi Mike,
This is the code, I used to connect to oracle from java. My
Oracle is 8i. Enterprise.
I have Oracle thin driver.
U need to start the lsnrctl (which is the Oracle listener from
your ORACLE_HOME/bin dir.
My program works.
If you have any prob, pl. do email me, I will help u.

MalaB

import java.sql.*;
import java.math.*;
import java.util.*;

public class DbConnection
{
String sql;
Connection conn;
Statement stmt;
ResultSet rs;

public Connection setConnection()
{
try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException cnf)
{
System.out.println("Error class not found");

}
try
{
//ORACLE is my sid
// since we are not on the network, we have to write localhost
// port 1521

conn = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:ORACLE",
"scott", "tiger");

}
catch (SQLException e)
{
System.out.println("Error SQLE in
getConn not found");
System.out.println("The Error is: " +
e.getMessage());


}
return conn;
}
public boolean ExecSql()
{
try
{
sql = "SELECT * from emp where empno =
7369";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
System.out.println("column2 = "
+ rs.getString(2));
System.out.println("column3= " +
rs.getString(3));

}
rs.close();
stmt.close();
conn.close();
}
catch (SQLException e)
{
System.out.println("\n**** SQLException
caught ***\n");
while (e != null)
{
System.out.println("SQLState: "
+ e.getSQLState());
System.out.println("Message: " +
e.getMessage());
System.out.println("Vendor: " +
e.getErrorCode());
e = e.getNextException();
System.out.println("");
}
}
return false;
}

public static void main(String args[])
{

DbConnection dbc = new DbConnection();
dbc.setConnection();
dbc.ExecSql();
}
}


0 new messages