Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle Connection - url

843854May 13 2003 — edited May 21 2003
Help!
My java application has database connection with oracle using Oracle thin driver. Currently this is my url which is in my properties file and the connectionBean accesses this properties file to connect.

url = jdbc:odbc:oracle:thin:@160:150:122:21:1521:alwf;
160:15:122:21 is the ip address of the database server. alwf is the SID; This works well but the database group changes the ip address every once in a while and they do not let the developers know; I am sure there is a way to connect it to the server without the ip address. Please help if you know a way.
Thanks
Sue

Comments

843854
Help! desperate!
Is there anybody who knows the answer to this question? please help!
Sue
843854
There is no way. If you don't know the IP address of the server, then your application cannot connect to the server. It's like trying to send an email to your boyfriend when you don't know what his email address is.

This really is something you have to take up with your manager. If the database administrators keep changing the IP address, then a lot of the programs you write will break through no fault of yours. Your manager will have to tell them to create a permanent address and stick with it.

The alternative is to probe the company-wide network looking for all available Oracle databases, and you can trust me, your company will much rather force the database administrators to stick with an address, than to have several different users all trying to find the database that they need.
843854
url =
jdbc:odbc:oracle:thin:@160:150:122:21:1521:alwf;
160:15:122:21 is the ip address of the database
server. alwf is the SID; This works well but the
database group changes the ip address every once in a
while and they do not let the developers know;
Probably because they're expecting you to connect using the server name not its IP address. The server name would remain the same but the IP address that the name resolves to could change. This should all be taken care of by a domain name server on your network.
843854
Exactly. They are expecting me to connect using the server name since the server name will not change. You are saying that it should be taken care of by a domain name server on my network. What do I use in my url string? instead of ip address, do i use the server name with all other parameters remain the same? can you make it a bit clearer?
Thanks
Sue
DrClap
Yes. You just replace the IP address by the server name, like this:

url = jdbc:odbc:oracle:thin:@oraclebox:1521:alwf;
843854
Thanks Dr.Clap for the answer. But the server also changes and the database group would like us to use a sqlnet connection string which is also tnsnames entry. This will be a pointer to the server. The pointer's name never changes even if the server changes. how do i use this in this url string?
Sue
843854
Thanks Dr.Clap for the answer. But the server also
changes and the database group would like us to use a
sqlnet connection string which is also tnsnames entry.
This will be a pointer to the server. The pointer's
name never changes even if the server changes. how
do i use this in this url string?
Sue
From the README that comes with the JDBC driver:

For the JDBC OCI8 Driver:

Connection conn = DriverManager.getConnection(
"jdbc:oracle:oci8:@<database>",
"scott", "tiger");

where <database> is either an entry in tnsnames.ora or a SQL*net
name-value pair.

For the JDBC Thin Driver, or Server-side Thin Driver:

Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@<database>",
"scott", "tiger");

where <database> is either a string of the form
<host>:<port>:<sid> or a SQL*net name-value pair.
843854
Thanks a lot Colin. I will try and see whether it works.
843854
Thanks a lot Colin. I will try and see whether it
works.
This did not work. don't understand why. Anybody - any ideas. please help!
Sue

843854
What didn't work? If you have a valid TNSNames entry and can connect to your database through SQL Plus, then Java will work. If SQL Plus won't work, neither will Java.

If your TNSNames entry is being invalidated when your networking group changes the hostname and IP of the server to which you need to connect, you're going to have to figure out a way to update your TNSNames on the fly or make it their responsibility to do so.

Whatever your network situation, you should be able to set up your workstation to copy a master TNSNames file to your $ORACLE_HOME\Network\Admin folder when a user logs in. The Database people can control the master file and the system administrators can make sure the file is copied on login. Make sure the NAME of the connection never changes and your code shouldn't have to deal with a thing, other than making sure that the OCI driver is used.

Again, what does "This did not work" mean?
843854
Or take a closer look at the information Dr. Clap quoted. If you are using the thin driver, you must provide either:

1) the database name in the format <ip or name>:<port>:<sid>

or

2) the SQL-NET name-value pair.

It appears that the administrators want you to use the SQL-NET name-value pair, but what that is, I have no idea. I get the impression from Dr. Clap's note that this is not the same thing as the TNSNames entry - see the section on the "thick" driver, it actually says to use one or the other.
843854
I can connect to the database through SQL Plus with a host string say dept_conn
but when i use this in my url variable to connect to oracle then it does not.
my url string goes like this:

url=jdbc:oracle:thin:@dept_conn:1521:dptc
Sue
843854
SQL Plus is using the given host name to do a lookup in the TNSNames file; if you find the same entry (dept_conn) in TNSNames you can use the same host and port values listed there.
dept_conn.WORLD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(Host = some.host.com)(Port = 1521))
    (CONNECT_DATA =
      (SID = ORCL)
    )
  )
becomes "jdbc:oracle.thin:@some.host.come:1521:ORCL". If this doesn't work with the thin driver then please post the error message it gives you.
1 - 13
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 18 2003
Added on May 13 2003
13 comments
603 views