I am trying to work on a project for school from home. The school computer has Oracle and I am trying to access it from home using Java/JSP. Currently I have Java SE with NetBeans installed on my home machine (Windows XP SP II), but not Tomcat or Oracle. The database that I am accessing is stored completely on the Oracle machine at school. One question I have is, given that, must I install Oracle at home too in order to get these JDBC drivers or do the drivers come with Java?

Researching the web, the solutions have involved setting up path and classpath with directories including ORACLE_HOME, which I believe does not exist on my computer since I have not installed Oracle. Here is the code I have written:

// Filename : DeptTableInteraction.java

package DBinteraction;

import java.sql.* ;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.*;

public class DeptTableInteraction 
{
    public DeptTableInteraction ()
    {
        System.out.println ("So Far So Good 1\n");
        try 
        {
            System.out.println ("So Far So Good 2\n");
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println ("So Far So Good 3\n");
        } 
        catch (ClassNotFoundException ex) 
        {
            System.out.println ("Something Bad Happened\n");
        }
    }
    public static void main(String[] args) throws SQLException 
    {
        DeptTableInteraction dti = new DeptTableInteraction();
    }
}

It compiles. The results are the following after compiling/running through NetBeans:

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Bob\NetbeansProjects\Java\DeptTableInteraction\build\classes
compile:
So Far So Good 1

So Far So Good 2

Something Bad Happened

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
debug:
BUILD SUCCESSFUL (total time: 1 second)

So the questions are:
1) Do I need to install Oracle on my local machine even though the database is stored elsewhere?
2) Where does this driver come from (Oracle or Sun)?

Thank you.

Do you have the oci or the thin Oracle Driver. If you have the oci driver, then yes, I believe you do need to have an Oracle client install on your machine (at least you don't need a complete Oracle install, just a couple of libraries and a few config files). If you have the thin driver, then you don't need that (it has less functions, fromwhat I've heard, than the oci Driver, but I've never missed them). If you have the oci Driver, then I would say to dowload and use the thin Driver.

Thanks for the response. I believe that the driver that I need is the "thin" driver. Some code from someone else that I am sort of using as a skeleton is this:

Connection conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@"school-server-address":1521:orcl",
        "oracle-user-id", "oracle-password");

Like I said, Oracle is not currently installed. However, I do have a file called "ojdbc14.jar", which came from an earlier Oracle installation. I have heard that this may be the right file for these drivers? So this driver, since it can came with an Oracle install, was written by Oracle rather than Sun? Basically I haven't tried to use this jar file because one, I don't know whether I'm supposed to use it or if there is some driver that was installed when I installed Java that I am supposed to use instead, and two, if I am supposed to use it and it contains what I need, where do I put it and how do I access it?

That is the thin driver, and yes you need to use it.

Place it anywhere you want to place it, and refer to it on the CLASSPATH.

O.K., I put the jar file on my Desktop for now and changed the "Properties" section of my project in NetBeans so that the "compile" tab adds that jar file. I'm still learning how to set the classpath so I'm not sure whether I actually did that or not (sometimes NetBeans figures out a lot for you). I'm going to experiment around. Regardless, doing that appears to have worked. I ran a slightly longer test program than what I posted and was able to create a new database table on the remote computer's Oracle database from my home machine hundreds of miles away. All of my "try" code worked and nothing was "caught" so hopefully it's all good. That was a small example and hopefully things will work as the project gets more elaborate. But for now it's working!

Thank you very much.

Adding to the "build" path on Netbeans is adding to the classpath (at least within Netbeans).

And mind that the thin driver consists of 2 jar files for recent versions (1 for really old versions), the names of which depend on the version of Oracle being used.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class test2 {
		public static void main(String args[])
		{
			Connection con;
			Statement stmt;
			ResultSet rs;
			String str;
			try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

				
				String serverName = "127.0.0.1";
			    String portNumber = "1521";
			    String sid = "21";
			    String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
			    System.out.println(url);
			    String username = "system";
			    String password = "bhopal";
			    con = DriverManager.getConnection(url, username, password);
			    System.out.println("CONNECTED");
			    
			    
				//con=DriverManager.getConnection("jdbc:odbc:");
				System.out.println("Connection successful");
				stmt=con.createStatement();
				rs=stmt.executeQuery("select * from userdetails");
				while(rs.next())
				{
					str=rs.getString(1);
					System.out.println(str);

				}
			}
			catch(Exception ex)
			{
				System.out.println("no");
			}
		}
}

Okay? What is that suppossed to be?

In any case, killing this zombie now. If you have a question start a new thread, please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.