AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Sample Java code requested

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Jack
Guest





PostPosted: Thu Nov 13, 2003 3:10 pm    Post subject: Re: Sample Java code requested Reply with quote




Include ojdbc14.jar in your CLASSPATH



Quote:
I get the following error message:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at SQLTest.main(SQLTest.java:10)
Caught Exception: oracle.jdbc.driver.OracleDriver




Back to top
Rick Wessman
Guest





PostPosted: Thu Nov 13, 2003 5:23 pm    Post subject: Re: Sample Java code requested Reply with quote



In article <bp00f3$1hu99r$1 (AT) ID-73292 (DOT) news.uni-berlin.de>, Bjorn Abelli says...
Quote:

"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


Another advantage of using parameterized statements is that the application

won't be as susceptible to SQL injection attacks. In a SQL injection attack the
user adds code to the statement which causes the app to retrieve data that the
user otherwise should not see.

Rick

Rick Wessman
Oracle Corporation
The opinions expressed above are mine and do not necessarily reflect
those of Oracle Corporation.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.