JDBC, i think i'm missing something - Please Read

Hi Guys!How can i get java to recognize the Package oracle.jdbc.driver. i can't even compile my code, i get the error:package oracle.jdbc.driver does not existimport oracle.jdbc.driver.*;
[216 byte] By [sunJavaa] at [2007-10-2 7:59:57]
# 1
u have to import a package like import java.sql.*;for this you have to set classpath for classes111_01.jar. It contains the drivers.
sum2005a at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

> Hi Guys!

>

> How can i get java to recognize the Package

> oracle.jdbc.driver. i can't even compile my code, i

> get the error:

> package oracle.jdbc.driver does not exist

> import oracle.jdbc.driver.*;

You should not be importing oracle classes. You should only need them at runtime. JDBC is set of interfaces which abstract you from having to build only for a specific database.

The only exception is if you are doing something that absolutley requires the use of vendor specific stuff. Like Oracle Blobs I think.

But generally importing specfic driver packages is a no-no.

If you really need to (because of the exceptional condition) then you need to add the things (jars, zips or whatever) with the Oracle driver to your classpath the same way you have added them to your classpath when you run your program.

sum2005a at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

u have to import a package like

import java.sql.*;

for this you have to set classpath for classes111_01.jar. It contains the drivers.

Yeah! ive got the import java.sql.*; statement in my code. i've set the class path on the command prompt like this:

set classpath=.;c:\oracle\ora92\jdbc\lib\classes111.zip;c:\oracle\ora92\jdbc\lib\charset11.zip;c:\oracle\ora92\jdbc\lib\ojdbc14.jar

any suggestions?

sunJavaa at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Yes don't do that. See reply 2. Also because setting the classpath as environment variable is a bad idea anyway.

Do this instead

javac -classpath .;otherjaryouwanttohave.jar YourSourceFile.java

But really do read reply 2. It was full of good advice even if you didn't at first glance seem to think so.

sunJavaa at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Gosh! a new set of problems now.

I'm trying to run one of the jdbc programs from the java tut, CreateCoffees.java

I got the error:

ClassNotFoundException: oracle.jdbc.driver.OracleDriver

SQLException: No suitable driver.

the line in my code reads:

try {

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

...

...

any suggestions? please.

sunJavaa at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
> ClassNotFoundException: oracle.jdbc.driver.OracleDriver> SQLException: No suitable driver. The Oracle driver jar isn't in your classpath at execution time.
StuDerbya at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
The Oracle driver jar isn't in your classpath at execution time.Can you please suggest me what path must i include in my classpath so as to have the oracle driver jar available?
sunJavaa at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

It's wherever you put it. Or wherever your Oracle installer put it.

For example, on my machine the appropriate driver for my version of Oracle is in C:\oracle\ora92\jdbc\lib - see if you've got a similar directory. Note that it's the JAR file that has to be on the classpath, not just the directory containing it.

If you haven't put it on your machine, and you haven't installed the Oracle client software, then you might not have it at all.

If you don't understand the above, you need to learn more about the classpath before trying to get a database connection working. Walk first, run later.

Dave.

dcmintera at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

> > Hi Guys!

> >

> > How can i get java to recognize the Package

> > oracle.jdbc.driver. i can't even compile my code,

> i

> > get the error:

> > package oracle.jdbc.driver does not exist

> > import oracle.jdbc.driver.*;

>

> You should not be importing oracle classes. You

> should only need them at runtime.

Unless you need to use something specific to Oracle which the general interface does not cover. For instance some of the complex types that Oracle allows.

jschella at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

> > > Hi Guys!

> > >

> > > How can i get java to recognize the Package

> > > oracle.jdbc.driver. i can't even compile my

> code,

> > i

> > > get the error:

> > > package oracle.jdbc.driver does not exist

> > > import oracle.jdbc.driver.*;

> >

> > You should not be importing oracle classes. You

> > should only need them at runtime.

>

> Unless you need to use something specific to Oracle

> which the general interface does not cover. For

> instance some of the complex types that Oracle allows.

Please actually read an entire post. I did say in the very next paragraph "The only exception is if you are doing something that absolutley requires the use of vendor specific stuff. Like Oracle Blobs I think."

jschella at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11

>

> Please actually read an entire post. I did say in the

> very next paragraph "The only exception is if you are

> doing something that absolutley requires the use of

> vendor specific stuff. Like Oracle Blobs I think."

Argghhh....yes I suppose it would help if I read the entire thing.

jschella at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12

> Can you please suggest me what path must i include in

> my classpath so as to have the oracle driver jar

> available?

It has to be the same way as scsi-boy suggested for compilation.

java -classpath "all the classpath directories and jars here" ClassName

aniseeda at 2007-7-16 21:51:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...