Well, everytime i want to use Database in my Java app, i have to go to ODBC to select my database and add it. But my application couldnt locate the database if i move it to another folder..

so how am i suppose to make it like, no matter which folder i move my database, my application can still locate it? cause i couldnt tell where the user will put the application files and database..
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
are we talking about an access db?
InNoCenT_Ch1ldAuthor Commented:
wait, are you trying to "say" that only MS Access has this stupid problem?
Mick BarryJava DeveloperCommented:
not sure if its only access (probably not) but yes it is an access problem, because in your dsn you specify the location of the access db file. If you move it you need to update your dsn.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

InNoCenT_Ch1ldAuthor Commented:
so, how to avoid it? or should i use other db software?

normally how you guys do with your database? cause i dun want to set the User DNS.. (can it be done with another db?)
Mick BarryJava DeveloperCommented:
if you don't want to use a DSN then you can specify the filename in your connection string. But you can't avoid specifying the filename somewhere as it needs to know where it is so it can be accessed.

Other DBMS (eg. mysql, SQL server etc) do not require you to specify a filename because the db is communicated with using sockets and not by directly accessing the filesystem.
InNoCenT_Ch1ldAuthor Commented:
guess i have to "quit" the stupid MS Acess already... ;(
InNoCenT_Ch1ldAuthor Commented:
btw, what you mean by "the db is communicated with using sockets "?
1.  You could have a properties file and put the filepath there.
2.  You could pass the connection string or the filepath in as a command line arg.

Depends on what your app does and how secure it has to be. This is terrible for security, but it would allow you to easily modify where the database is without hardcoding it in your source code or changing the dsn.

It's not a good idea to be moving the database file around. If you need to change it because you are deploying to another computer, there is probably a way to use relative path names rather than absolute path names ( "..\database.mdb" instead of "C:\Java\Myapp\Mydatabase\database.mdb"

Mick BarryJava DeveloperCommented:
> what you mean by "the db is communicated with using sockets "

instead of accessing the db file directly, instead the interaction with the database is performed by connection to the database application.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.