Board index » jbuilder » how to set a relative path to a JDataStore Database

how to set a relative path to a JDataStore Database


2003-11-03 05:52:35 AM
jbuilder2
Hi,
I am using an offline database for my application.
The path to the databases is something like
D:\projects\project1\source\db\db.jds
When I compile the application and create an archive from it, it does
not find the databastore when I distribute it.
The only thing that works is to add the db in the same path on the other
system.
Is it possible to create a relative path like \\source\\db\\db.jds so
that it finds the database when I copy it to another system?
Also; is it possible to add the database to the archive?
Thanks,
Roel
 
 

Re:how to set a relative path to a JDataStore Database

Roel wrote:
Quote
Hi,

I am using an offline database for my application.
The path to the databases is something like
D:\projects\project1\source\db\db.jds
When I compile the application and create an archive from it, it does
not find the databastore when I distribute it.
The only thing that works is to add the db in the same path on the other
system.
Is it possible to create a relative path like \\source\\db\\db.jds so
that it finds the database when I copy it to another system?

Also; is it possible to add the database to the archive?

Thanks,

Roel
If you create a properties file, you could put the path information in th
properties file, and read from this file to get the path.
The other option would be to create some type of descriptor file (like XML,
for example) that would read and load the path info from that file.
If you are worried about secueity (plain text or XML), you could use a
serialized object to write the info as a binary stream.
 

Re:how to set a relative path to a JDataStore Database

In <3fa57ca8$ XXXX@XXXXX.COM >Roel wrote:
Quote
I am using an offline database for my application.
The path to the databases is something like
D:\projects\project1\source\db\db.jds
When I compile the application and create an archive from it, it does
not find the databastore when I distribute it.
The only thing that works is to add the db in the same path on the
other system. Is it possible to create a relative path like \\source\\
db\\db.jds so that it finds the database when I copy it to another
system?
There's a fairly direct way of ascertaining just
where your database is if you package/archive it
up in a JAR.
Suppose the root of your package structure is
the "source" directory, and you have your jds
file in the "db" directory as described above.
First, add the jds file to your project.
Next, right-click on the jds file node in
the Project Pane, select Properties... .
You will be presented with the "Build" properties
which basically allow you to specify what is done
with this resource when your project is compiled.
Click on both Copy radio buttons. OK.
The next time you compile, the jds file will be
copied to your output directory, which under
normal circumstances is the "classes" folder.
Now, in a small test program (you can put all
the code below in the main, and do nothing with
the rest of the simple little class you create
using File>New>Class.
package db;
public class MyTest {
public static void main(String [] args) {
try {
jbInit();
URL url = db.MyTest.class.getResource("db.jds");
if ( url != null ) {
File f = new File(url.getFile());
System.out.println("path of db.jds: " +
f.AbsolutePath());
System.out.println("f.getParent()=" +
f.getParent());
System.out.println(
"this.getClass().getPackage().getName()=" +
this.getClass().getPackage().getName());
}
else
System.out.println("url is null");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
I think that if you look at what is available to
you in the information, you should be able to
construct the path to the database, even if
you do something like this
d:/projects
/myproject
/classes
/data
- db.jds
/source
/db
- MyDataModule.java
In the case where the resource is an entirely
different folder path, use this expression
url = db.MyTest.class.getResource("MyTest.class");
to get started.
Quote
Also; is it possible to add the database to the archive?
I think that a little reading in the on-line Help should
answer this question. Look up "archive" in the Index
tab, and go to "deploying files" or something like that.
Look for a link to "Resources".
There's a slight trick if you want to put the db.jds
in something like the "data" folder illustrated above.
1. Remove the "Copy", "Copy" from the file node's
properties.
2. In the archive node's properties, add the resource
there.
3. Make sure you "Clean" both the Project node and
the archive node.
4. Finally, rebuild/make your archive.
Paul Furbacher [TeamB]
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

{smallsort}

Re:how to set a relative path to a JDataStore Database

Roel wrote:
Quote
Hi,


Also; is it possible to add the database to the archive?

Thanks,

Paul F. answered this part of the question. The answer I gave, would allow
you to have the database reside locally or on a network.
 

Re:how to set a relative path to a JDataStore Database

Thanks guys
Roel wrote:
Quote
Hi,

I am using an offline database for my application.
The path to the databases is something like
D:\projects\project1\source\db\db.jds
When I compile the application and create an archive from it, it does
not find the databastore when I distribute it.
The only thing that works is to add the db in the same path on the
other system.
Is it possible to create a relative path like \\source\\db\\db.jds so
that it finds the database when I copy it to another system?

Also; is it possible to add the database to the archive?

Thanks,

Roel

 

Re:how to set a relative path to a JDataStore Database

JDataStore complies with the java.io.File convention of using the System
property of "user.dir" to resolve relative paths.
So if you set this property up front, JDataStore and the rest of your app
will resolve relative paths with the user.dir property setting.
See the java doc of java.io.File for more details.
--
-- Steve
-- JDataStore and DataExpress Development Team
-- sshaughnessy at borland software
"Roel" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks guys


Roel wrote:

>Hi,
>
>I am using an offline database for my application.
>The path to the databases is something like
>D:\projects\project1\source\db\db.jds
>When I compile the application and create an archive from it, it does
>not find the databastore when I distribute it.
>The only thing that works is to add the db in the same path on the
>other system.
>Is it possible to create a relative path like \\source\\db\\db.jds so
>that it finds the database when I copy it to another system?
>
>Also; is it possible to add the database to the archive?
>
>Thanks,
>
>Roel
>