Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / July 2005

Tip: Looking for answers? Try searching our database.

JDBC URL for Oracle Database With Failover (2 db servers)

Thread view: 
johnhurt@gmail.com - 27 Jul 2005 00:59 GMT
Ok,

The DB URL typically looks like...

jdbc:oracle:thin:@HOSTNAME:1521:SID

But what if my database has failover and there's actually 2 hosts that
I could have?

SAMPLEDB.world=
 (Description=
   (failover=on)
   (address=(protocol=tcp)(host=server001)(port=1521))
   (address=(protocol=tcp)(host=server002)(port=1521))

(Connect_data=(service_name=SAMPLEDB)(failover_mode=(type=select)(method=basic))))

Would I have to just specify 1 of the hosts? Or is there some other way
to have it use the TNS names installed on the client and have that take
care if it?  Thanks.
jeak110 - 27 Jul 2005 17:36 GMT
of cource you there is!!!

2.3.3 Formulating a Database URL
After you've loaded the driver, you can establish a connection using
the
DriverManager.getConnection( ) method. This method is overloaded and
therefore has
various forms. However, each form requires a database URL. A database
URL is an address that
points to your database. Formulating a database URL is where most of
the problems associated
with establishing a connection occur. For Oracle, the database URL has
the following general
form:
jdbc:oracle:driver:@database
database ::= {host:port:sid | net_service_name | connect_descriptor}
which breaks down as:
driver
Specifies the type of JDBC driver to use for the connection. The
following choices are
available:
oci7
For the Oracle 7.3.4 OCI driver
oci8
For an Oracle 8.x.x OCI driver
oci
For an Oracle 9.x.x OCI driver
thin
For the Oracle Thin driver
kprb
For the Oracle internal driver
database
Specifies the database to which you want to connect. You can specify a
host, port, and
SID; a net service name; or a connect descriptor.
host:port:sid
Used only with the Thin driver and identifies the target database using
the following
information:
host
The TCP/IP address or DNS alias (hostname) for your database server
port
The TCP/IP port number of the Oracle listener
sid
The System Identifier of your database
net_service_name
Used only with the OCI driver. A net service name, or tnsnames.ora file
entry as it is
commonly known, is a short name that resolves to a connect descriptor,
which is a
specially formatted Net8 database address. Net service names are often
resolved via a
local file named tnsnames.ora but may also be resolved using
centralized methods such
as Oracle Names. The OCI driver depends on the Oracle Client software
to be able to
resolve a net service name. That's why net service names are used only
with the OCI
driver.
connect_descriptor
Can be used by either driver and is a Net8 address specification such
as that normally
found in a tnsnames.ora file.
Now that you know the rules of how to formulate a database URL, let's
look at several examples
as we explore the overloaded forms of the getConnection( ) method.

it's from
Java Programming with Oracle JDBC
Donald Bales
Publisher: O'Reilly
First Edition January 2002
ISBN: 0-596-00088-x, 496 pages
By GiantDino

I have not time to write a full answer ... sorry ... just send me a
message to my email if you have any  question. I'll try to help you!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.