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

Home -> Community -> Usenet -> c.d.o.server -> Re: A little help connecting to oracle from java. Anyone? Please!!? :-)

Re: A little help connecting to oracle from java. Anyone? Please!!? :-)

From: Anurag Varma <avdbi_at_hotmail.com>
Date: Sat, 10 Aug 2002 15:58:30 -0400
Message-ID: <Cje59.123359$D8.4179012@news4.srv.hcvlny.cv.net>

Comments below:

Anurag
"Simon Harvey" <noThanks_at_pdf.com> wrote in message news:3d554318_1_at_news.teranews.com...
> Hi,
>
> I'm having problems conecting to an oracle database using jdbc and I was
> wondering if you could help.
>
> The only way I know how to connct to a database (MS Access in particular)
is
> to create a DSN in the Windows control panel applet called Data Sources
> (ODBC) and then use that name as part of the connection string in my java
> program.
>
> But with oracle I'm getting a bit confused as I'm not sure if using this
> method comes into it at all (I hope it does cos it's easy!!) I've read
that
> instead of using the DSN, you just use the service name. Now service names
> scare the crap out of me as I dont understand them.
>
> Well, I've tried both now (I think (not sure if I got the service name
> right)) and each time I'm getting:
>
> java.sql.SQLException: Io exception: Connection
>

refused(DESCRIPTION=(TMP=)(VSNNUM=150999297)(ERR=12505)(ERROR_STACK=(ERROR=(
> CODE=12505) (EMFI=4))))
>
>
> I've tried the following two connection strings:
>
> DSN Version:
> String connectionString = "

jdbc:oracle:thin:localhost:1521:daytonDSN";
>
> What I think is the Service Name version:
> String connectionString = "
> jdbc:oracle:thin:localhost:1521:dayton.homenet";
> also tried:
> String connectionString = " jdbc:oracle:thin:localhost:1521:DAYTON";
>
>
> I dont know which is the actual service name as I've been told to
differing
> things. Could someone take a sec just to tell me once and for all!!
Please!
>
> Where the relevant part in my TNS.ora is:
>
> DAYTON = **** Is this the Service Name******
> (DESCRIPTION =
> (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP)(HOST = aegis)(PORT = 1521))
> )
> (CONNECT_DATA =
> (SERVICE_NAME = dayton.homenet) ******* Or is this the
Service
> Name********
> )
> )

I thought it was clear in its definition: SERVICE_NAME=dayton.homenet ..... then dayton.homenet is the service name. DAYTON is however the tnsname which is the alias used by the Net*8. Java thin driver however does not refer
to tnsnames.ora.
However in your case, you can use the above tnsname entry to find out if you *can* connect to the database. Considering the the above tnsname definition works
in your case then try this in java:
jdbc:oracle:thin:aegis:1521:dayton.homenet

Thus it is:
jdbc:oracle:thin:<hostname>:<port>:<service_name>

You have either of the three things wrong: <port> = 1521
hostname = localhost / ip address / hostname service_name = service_name of your database. If unsure about this then either

                          query the database and/or listener.ora and/or
figure it out
                          by connecting via sqlplus and using tnsnames.ora
entry.

Note that Java thick odbc drivers do use the tnsnames.ora. So you can try that way also.

>
>
> You have know idea how much it would mean to me to get this sorted out. I
> was hoping that comething as simple as connecting to the database would be
> easy to do right out of the box but this has had me, my girlfriend and one
> of my best mates bamboozled for weeks.
>
> My (and our) sincerest thanks to anyone who knows what all this means and
> how to fix it. I know its going to be something so trivial but its so
> frustrating!!
>
> Thanks again
>
> Simon
>
>
>
>
>
>
>
>
>
Received on Sat Aug 10 2002 - 14:58:30 CDT

Original text of this message

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