Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Sample Java code requested

Re: Sample Java code requested

From: Bjorn Abelli <DoNotSpam.bjorn_abelli_at_hotmail.com>
Date: Thu, 13 Nov 2003 14:20:34 +0100
Message-ID: <bp00f3$1hu99r$1@ID-73292.news.uni-berlin.de>


"Brad" wrote ...

First, please don't crosspost.

[I have set Follow-up to comp.lang.java.databases only]

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

When you're using Class.forName(...), the compiler doesn't look for the existence of the driver.

> Statement st = conn.createStatement();
[...]
> sSQL = sSQL + " WHERE ename = '" + args[0] + "'";

Not that your concatenation wouldn't work, but it's better practice to use parameterized statements instead. Further along you will probably run into problems where concatenation won't work.

Look in some tutorial for "PreparedStatement".

> It seems to compile OK when I use:
> javac SQLTest.java

As I wrote above...

> My CLASSPATH has been set as (I copied the Oracle .zip
> files into my $HOME directory as .jar files after
> reading somewhere that sometimes the
> difference could be in the file extension not being '.jar'???) :

Well, that's wrong, although it should work either way. You should use the zip-files as they are, but why are you including *all* of them?

>

./classes12.jar:./classes111.jar:/apps/oracle/8.1.7/jdbc/lib/classes111.zip:
> /apps/oracle/8.1.7/jdbc/lib/classes12.zip:/usr/java/jre/lib/rt.jar

Which driver to include depends on which Java JVM you're using:

before SDK 1.2: classes111.zip
SDK 1.2 - 1.3: classes12.zip
SDK 1.4: ojdbc14.jar

What version of the Java SDK are you using? If it's 1.4 I suggest you go to Oracle's website and download ojdbc14.jar and use that instead.

> And I execute the above using the following:
>
> java -cp . SQLTest TURNER

Ouch! That raises some questions about your classpath and what version of Java SDK you're using.

Depending on which version of the JVM you're using it's more or less necessary to include the whole classpath into the cp-switch. The CLASSPATH itself shouldn't even have to exist if you're using SDK 1.2 or later. The JVM should find it's own classes anyway.

  1. Don't use relative paths in your CLASSPATH-variable!
  2. It's better practice to include the driver in the cp-switch when you execute the program.

// Bjorn A Received on Thu Nov 13 2003 - 07:20:34 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US