aspose file tools*
The moose likes JDBC and the fly likes jdbc driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc driver" Watch "jdbc driver" New topic
Author

jdbc driver

Anonymous
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:
URL:
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.
zhongwwu

Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
"zhongwu"
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . 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.
Thanks.
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
jdbcracleci8:@
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:
jdbc.drivers=oracle.jdbc.driver.OracleDriver
myapp.dburl=jdbcracle:thin:@
myapp.host=localhost
myapp.port=1530
myapp.sid=DBName
Then in your application code you can do this:
InputStream in = getClass().getResourceAsStream("path_to_properties_file");
System.getProperties().load(in);
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("myapp.host") + ":" +
System.getProperty("myapp.port") + ":" +
System.getProperty("myapp.sid");
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:
URL:
jdbcracle:thin:@serverName:portNumBName
But if I want to use just generic name like
jdbcracle:thin:@DBName
it does not work for me.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc driver