Link to home
Start Free TrialLog in
Avatar of MicheleMarcon
MicheleMarconFlag for Italy

asked on

Persistence Unit JDBC with custom path

With NetBeans 6.0, I have a persistence unit with this connection jdbc:firebirdsql:localhost:c:/database/user.fdb

I want to change the c:/database/user.fdb path so that is set at installation time or at run time.

This is because I cannot force the user to put the database on a fixed path, but I want it to be on the home folder or the Programs folder
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="user.fdbPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>pvconfigurator.Moduli</class>
    <properties>
      <property name="toplink.jdbc.user" value="SYSDBA"/>
      <property name="toplink.jdbc.password" value="masterkey"/>
      <property name="toplink.jdbc.url" value="jdbc:firebirdsql:localhost:c:/database/user.fdb"/>
      <property name="toplink.jdbc.driver" value="org.firebirdsql.jdbc.FBDriver"/>
    </properties>
  </persistence-unit>
</persistence>

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Probably best to put it in ${user.home} and get that as a system property
Try the following and set if it works:
jdbc:firebirdsql:localhost:${user.home}/user.fdb

Open in new window

Avatar of MicheleMarcon

ASKER

Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544344. I/O error for file CreateFile (open) "${user.home}/user.fdb"
Error while trying to open file
null
Reason: I/O error for file CreateFile (open) "${user.home}/user.fdb"
Error while trying to open file
null
Error Code: 335544344
        at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305)
Of course, I copied the user.fdb on the home folder first.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK then, how could I set it dynamically? (I'm using netbeans 6)
Or, different solution: how do I convert the xml into code?
    PersistenceUnit getPU(){
    return new PersistenceUnit() {
 
            public String name() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public String unitName() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public Class<? extends Annotation> annotationType() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };
    }

Open in new window

Quite simply i don't know how you'd do it in code using that form of config
:-)