problem connecting to oracle database

I'm having a really basic problem with connecting to oracle.

I've made sure that the driver is being found by the program, but it always errors when trying to connect.

CLASSPATH=C:\oracle\product\10.2.0\db_1\jdbc\lib;C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar;C:\Program Files\Oracle\jre\1.1.8\bin;C:\j2sdk1.4.1_05\bin;C:\jakarta-tomcat-4.1.29\bin;C:\jakarta-tomcat-4.1.29\common\lib\servlet.jar;

I'm running Oracle 10.2, and have j2sdk1.4.1_05

code is as follows:

package studyC;

import java.io.*;

import java.sql.*;

publicclass test

{

publicstaticvoid main (String[] args)

{

Connection con =null;

PreparedStatement s =null;

ResultSet res =null;

try

{

Class.forName("oracle.jdbc.driver.OracleDriver");

System.out.println("driver loaded");

String url ="jdbc:oracle:thin:@192.168.2.252:1521:ORCL2";

String username ="system";

String password ="manager";

con = DriverManager.getConnection(url, username, password);

System.out.println("database connected");

s = con.prepareStatement("SELECT * FROM C_2;");

System.out.println("got here");

res = s.executeQuery();

while (res.next())

{

System.out.println(res.getString("code") +"\t" + res.getString("name"));

}

}

catch (Exception e)

{

C12_Log.write(1, e.toString());

}

finally

{

try

{

if (s !=null)

{

s.close();

}

if (con !=null)

{

con.close();

}

}

catch (Exception es)

{

C12_Log.write(1, es.toString() + es.getMessage());

}

}

}

}

and I get the following output when I run 'java studyC.test' from the folder above my package folder.

driver loaded

Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at studyC.test.main(test.java:28)

and line 28 is the one with the connect, I took out comments for readability.

If anyone could help out with this I'd be grateful.

[4641 byte] By [lance_dragonsa] at [2007-11-27 7:08:37]
# 1

LD,

You don't need to set the CLASSPATH environment variable.

Personally, I prefer not setting CLASSPATH at all and using the "-classpath" option to the "java" command.

You only need to include the JDBC driver.

Your command should be:

java -classpath C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar test

Your error message states that class "java.sql.Savepoint" is not found.

I see the following in your CLASSPATH:

C:\Program Files\Oracle\jre\1.1.8\bin

I'm guessing you're probably running java version 1.1

Class "Savepoint" was introduced in java 1.4

Try the following command:

(Again, I recommend unsetting CLASSPATH first.)

java -version

If it doesn't say you're running java 1.4 then that explains the cause of your error message.

Also, I suggest visiting this Web page:

http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html

One of the links on that page is to the OTN forum on JDBC.

That forum contains an announcement that class "oracle.jdbc.driver.OracleDriver" is deprecated.

Here is the link:

http://forums.oracle.com/forums/ann.jspa?annID=201

The first URL I posted above has links to sample code as well.

It's not a good idea to do connect to the database as the SYSTEM user if you aren't intending to do administration work.

That's why Oracle supplies the sample SCOTT schema.

The login and password is usually "scott/tiger".

Story goes that the guy who developed the SCOTT schema is indeed called Scott and Tiger is the name of his cat. (Whatever ;-)

Good Luck,

Avi.

abramiaa at 2007-7-12 19:00:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Thanks a lot for the help, it looks like when I installed oracle, it was making use of an older java version than the one I had installed before, making that error appear. I took out a couple things in my classpath (I know I shouldn't use it, but I'm too lazy to type out full paths ^^;)

I didn't know that the java commands I was using could suddenly be overridden, but that java -version should be usefu for checking that now. I do have a user for the database connection, but I was trying to figure how to connect to the darned thing first, so I was making use of system.

Although it looks that the driver is deprecated, a lot of the systems I'll be dealing with probably haven't upgraded past Oracle 10.2 (some of them are 8 or 9), so I'll keep using it until I see a big upgrade. Anyhow, thanks for the help, this little problem had me confused for a long while.

lance_dragonsa at 2007-7-12 19:00:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...