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: Tom <trenfro_at_i-55.com>
Date: Sat, 10 Aug 2002 12:44:18 -0500
Message-ID: <aj3j5i$mgq$1@news.datasync.com>

> Hi,

Hello. :-)

>
> 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.
>

You can use the Oracle or Microsoft ODBC drivers for Oracle and set it up as a user/system DSN, but you still need your net service names set up correctly in tnsnames.ora.

> 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))))
>

CODE = 12505 means the listener on your database system doesn't recognize the service name or sid you specified in your tnsnames.ora net service name.

>
> 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";
>

Based on what you have below, your connectionString should be "jdbc:oracle:thin:@localhost:1521:DAYTON"

The last bit (DAYTON) is the "net service name"

>
> 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:

By default this should be tnsnames.ora, not TNS.ora, but if you can connect via sqlplus to the database, then it's fine, and there is some non-default setup going on.

>
> DAYTON = **** Is this the Service Name******

DAYTON is your "Net Service Name", oftentimes called just "Service Name". It names this connection for use in JDBC, SQL*Plus, and everywhere else on your local machine.

> (DESCRIPTION =
> (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP)(HOST = aegis)(PORT = 1521))
> )
> (CONNECT_DATA =
> (SERVICE_NAME = dayton.homenet) ******* Or is this the
> Service
> Name********

This is the actual "Service name". It names the database service set up on the database server side. The confusion between "Net Service Name" (for naming connections) and "Service Name" (for >= oracle 8i database services on a server) is annoying. You're not the first nor the last to get hit by it. When connecting to Oracle, always use the NET Service Name.

> )
> )
>
>
> 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

Best of luck...

-Tom Received on Sat Aug 10 2002 - 12:44:18 CDT

Original text of this message

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