dcsimg
Unable to Connect to Oracle Database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ram_M
Posted On:   Thursday, December 20, 2001 03:15 PM

Hi, I wrote a simple java class which connects to Oracle Database and displays data from an EMP Table. The Program is as follows.. package testservlet; import java.sql.*; public class TestServlet { public static void main(String[] args) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); String url = "jdbc:oracle:oci8:@"; try { String url1 = System.getProperty("JDBC_URL"); if (url1 != null) url = url1; } catch (Exception e) { } // Connect to the database Connection conn = DriverManager.getConnection (url, "   More>>

Hi,

I wrote a simple java class which connects to Oracle Database and displays data from an EMP Table.

The Program is as follows..

package testservlet;
import java.sql.*;
public class TestServlet {
public static void main(String[] args) throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

String url = "jdbc:oracle:oci8:@";
try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) { }

// Connect to the database
Connection conn =
DriverManager.getConnection (url, "scott", "tiger");

// Create a Statement
Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

// Query the EMP table
ResultSet rset = stmt.executeQuery ("select EMPNO, ENAME from EMP");

while (rset.next())
{
// We expect to see the three new employees
System.out.println (rset.getInt(1)+" "+rset.getString(2));
}
System.out.println ();

rset.close ();

// Close the Statement
stmt.close();

// Close the connection
conn.close();
}
}



But I was getting the following error.
oracle.jdbc.driver.OracleDriver not found.

I am using VisualAge editor to run this program. I have Oracle 8.1.7 Installed which consists of Classe12.zip and classes111.zip drivers. I added both these zip files into VisualAge's Window/Options/Resources.. Workspace Classpath..

But Still I am getting the above error.

Please let me know where i am going wrong and any steps that I am missing here.

Thanks in Advance,
Ram M

   <<Less

Re: Unable to Connect to Oracle Database

Posted By:   Arun_Bharathan  
Posted On:   Friday, December 21, 2001 11:58 AM

You don't have to add both the files to the classpath. Depending on VAJ version, add classes111.zip to only VAJ 3.0 and below. And add classes12.zip for other versions. And from the code i could see that it should be JDBC2.0 compliant (So classes12.zip) Check that classpath has been entered correctly. (spelling and all!)
Now next thing is that you are using OCI connectors so you should have the Oracle client installed (Better way is to use the thin client which is pure java Client).
About | Sitemap | Contact