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:
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 ]
posted 15 years ago
well, that didn't quite work out. that's supposed to be:
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.