Connecting to a database, without hard-coding the connection string

K

kaeli

Hey all,

(original thought that inspired this post over in c.l.j.d)

I'm trying to figure out the best way to do this.
My application (web and command-line companion tools) is growing much larger
than anticipated. I am looking at getting it into a good structure and going
with CVS, Ant, and all that jazz. As I was looking at that, I realized it was
going to hard to just plop a pre-built webapp onto my production server b/c I
hard-coded the connection string for my DB into one of my core classes. So it
needs changed, then recompiled, then put in place on the production machine.
I have to get that hard-coded connection string out of there.

#1: I don't want to use the Sun ODBC driver, b/c I heard bad things about it.
So, I'd like to stay with my Oracle driver. The test machine has no Oracle on
it, so no tnsnames.ora for a DSN. So, it would seem that the name would have
to either come from the system somehow, or a config file.

#2: No Struts. :(

#3: Must work standalone. No web.xml config unless non-jsp classes can also
use it somehow. I have helper apps using the same core classes. It is one of
those classes that handles the connections. If I read from some file I create
and name, somehow I must be able to know the location of that file to read it
in.

#4: I think I can use JNDI to connect to LDAP as well as a DB, something I
currently cannot do, but would like to. But I don't know enough about it to
know if the standalone class could use that. Can it?

So...
Thoughts? Opinions?
I don't currently use connection pooling. If JNDI uses that, it'd be an
additional upside to that solution. Note that I don't really know jack about
JNDI, so any comments on it as a solution, either yeah or nay, appreciated.
It just looked, well, more J2EE than J2SE. *g*

Environment: Sun Solaris (Unix), Oracle 8i, Java 1.4, JSP, IPlanet

--
--
~kaeli~
Any sufficiently advanced technology is indistinguishable
from magic.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top