File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes jdbc driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc driver" Watch "jdbc driver" New topic

jdbc driver

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a question about the URL for jdbc connection in EJB in Inprse app server.
It works if I have the following:
jdbc racle:thin:@serverName ortNum BName
But if I want to use just generic name like
jdbc racle:thin:@DBName
it does not work for me.
The main purpose is that I want the oracle naming server to resolve the database name, not to hardcode the port number and server name in my code.
BTW, I can connect to the database using sql plus 3.3 with the generic name, so I believe my oracle client setup is correct.
I am using oraclethin driver now, I wander if there is any other driver will support the generic name to access the database for the entity bean.

Any suggestion will be greatly appreciated.

Matt Midcap

Joined: Jan 07, 1999
Posts: 440
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Also, I think you will get a better responce to your question on the "JDBC" forum so I'm moving it there.

Best Regards,<br />Matt Midcap
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
The reason that you must specify the host, port and Service Name (or Service ID, SID) with the thin driver is that the thin driver is intended to be used over a network. Even if the database server is on the same machine as the Java application, the driver makes a network connection to the server. There is no way for the driver to determine the host, port, and service id from just the DBName. So, for the thin driver, you must always pass a host name and port as part of the connection url.
You can use the technique you are asking about if you are using the OCI driver. With the OCI8 driver you can specify the URL as
and the driver will connect to the database on the same machine.
If you are worried about hardcoding values into your code, then write your code without hardcoding the url, driver, or other parameters. There are many ways to pass configurable information into a class. One way is to use command line arguments; another way is to provide a user interface and have the user enter the parameters. One technique that I've used before for jdbc parameters is a properties file.
Here's an example properties file with dummy data:
Then in your application code you can do this:
InputStream in = getClass().getResourceAsStream("path_to_properties_file");
By specifying the driver in the properties file as jdbc.drivers and then storing it into the System Properties object, the driver will be automatically loaded by the DriverManager. All you need to do is get a connection:
String connecturl = System.getProperty("myapp.dburl") +
System.getProperty("") + ":" +
System.getProperty("myapp.port") + ":" +
Connection conn = DriverManager.getConnection(connecturl);
Originally posted by zhongwu:
I have a question about the URL for jdbc connection in EJB in Inprse app server.
It works if I have the following:
But if I want to use just generic name like
it does not work for me.

I agree. Here's the link:
subject: jdbc driver
It's not a secret anymore!