• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Database connection problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a project servlet whose purpose is to receive an xml file and, based on some characteristics of the xml, perform a set of operations on an Advantage Database (not exactly my database of choice, but it's not my decision). The servlet is running on resin, and I'm connecting to the database using the Jdbc-Odbc Bridge.
A little background on advantage (at least the version I have to use) -- there are no dictionaries or anything like that. Basically, a database is just a collection of .adt files in a directory.

Initially, I was working with one database. I set up a User DSN in the Windows Control Panel, entered in the directory of the databse in options, and gave it the name "Database". Then in my resin.conf, I put this:

<database>
<jndi-name>java:/BenDB</jndi-name>
<driver>
<type>sun.jdbc.odbc.JdbcOdbcDriver</type>
<url>jdbcdbc:Database</url>
</driver>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>

In my app, I connect to the database using it's jndi name -- java:/BenDB.

Here's the problem I'm having -- a field (call it i.d.) in the xml tells me which database (of many) I need to connect to. I have a properties file that is a mapping between ids and directories:

1=c:\firstDB\data
2=c:\secondDB\data
...

My question is, I guess, how can I change which database the getConnection() method connects to on the fly? I suppose I *could* create User DSN's and JNDI names for each of the databases (somewhere between 8 and 10) and bloat up my resin.conf, but that seems kind of distasteful. Any ideas?

[edited to disable smilies]
[ December 22, 2004: Message edited by: Jeanne Boyarsky ]
 
Ben Rainville
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, that didn't quite work out. that's supposed to be:

jdbc: odbc: Database
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,
Welcome to JavaRanch! I edited your post to disable the smilies for you. In the future, you can edit a post (it's the little icon that looks like a pencil and paper) to do this yourself. The disable smilies checkbox is in the options section (third section down) on the page.

On to your question: To use datasources, you do have to create the JNDI names in your configuration. 8-10 doesn't sound too bad though. If it is truly dynamic and you can't predict them, you would need to use the non-app server approach and get/manage the connections yourself. This is even messier than setting up all the datasources in advance.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic