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: JDBC and Oracle connection

Re: JDBC and Oracle connection

From: Malcolm Sparks <malcolm.sparks_at_littlewoods-stores.co.uk>
Date: 1997/11/07
Message-ID: <34635017.7E07F507@littlewoods-stores.co.uk>#1/1

Terje A Bergesen wrote:

> Hi.
>
> I am not an Oracle expert, but am currently playing a bit with
> Java and JDBC against Oracle. I have downloaded the new JDBC
> drivers from Oracle, and am trying to connect to it. Oracle is
> at 7.3.something.
>
> Connecting to the Oracle with sqlplus is usually done with:
> sqlplus user/pass_at_t:host:DB
>
> I then try to use the the JDBC/OCI drivers from Oracle, and
> I am a bit puzzeled as to what connection string I am supposed
> to use. Anything seems to fail...
>
> I have tried variations of
> Connection conn = DriverManager.getConnection (
> "jdbc:oracle:oci7_at_t:host:DB", user, password);
>
> and
>
> Connection conn = DriverManager.getConnection (
> "jdbc:oracle:oci7_at_host:DB", user, password);
>
> but none of them seems to work. I get an oracle error
> java.sql.SQLException: ORA-06401: NETCMN: invalid driver designator
>
> I do initialize the drivers, my example is straight from
> the JdbcCheckup.java example.
>
> I am probably just ignorant here, but would be thankful for
> any help.
>
> --
> ----------------------------------+-------------------------------------
> - Terje A. Bergesen | The UNIX Guru's View of Sex: -
> ----------------------------------+ -
> - Say NO to inferior technology. | # unzip ; strip ; touch ; finger ; -
> - Say NO to MS Internet Explorer. | mount ; fsck ; more ; yes ; -
> - Say NO to MS Visual J++ | umount; sleep -

First, don't use the OCI driver unless you have SQL*Net installed. Eg. Don't use "jdbc:oracle:oci7....".
Use the thin driver instead.
Eg. "jdbc:oracle:thin..."

Second, the order of parameters for the connection string is important. It goes host:port:sid. Remember that SQL*Net does the job of finding out which machine the database listener is on, and what TCP port number is used to connect. But since SQL*Net is not used you have to supply enough information to the driver for it to find the database itself.

From your examples, you've got a bit confused with the use of the colon. Perhaps this is because it was used in SQL*Net version 1 to specify protocol:host:sid. This is history now.

Third, I would specify your username and password in the connection string. Java concats strings fine, so why use parameters?

Therefore, this is your answer:

Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:scott/tiger_at_host:1521:DB");

(I've put the 1521 as the port since this is the default the listener uses, it will be specified in the listener.ora file on the server- check this if it doesn't work. DB is the sid name, host is the hostname)

If you want to use the OCI driver and you have SQL*Net v2 correctly installed and configured on your machine, you can use this:

Connection conn = DriverManager.getConnection ("jdbc:oracle:oci7:scott/tiger_at_sales");

(sales would be a service name found in a local tnsnames.ora file, or using Oracle Names, etc..)

Malcolm Sparks
Congreve Computing Received on Fri Nov 07 1997 - 00:00:00 CST

Original text of this message

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