2

I have a glassfish container managed derby database that I can access using CRUD operations. I would like to access my derby database directly through the asadmin tool to view the tables.

However, I cannot find my database.

After researching this site i see that glassfish creates connection pools that connect only when required. I see that it is possible for me to create a connection pool but I don't even know where the database is.

Any advice is greatly appreciated. I am new to JEE7 and learning from 'JEE7 for beginners' book.

<persistence-unit name="chapter15PU" transaction-type="JTA">
    <jta-data-source>jdbc/__default</jta-data-source>
    <properties>
        <property name="javax.persistence.schema-generation.database.action" value="drop-and-    create"/>
        <property name="eclipselink.logging.level" value="INFO"/>
    </properties>
</persistence-unit>
  • Can you figure out what your "JDBC Connection URL" is? It should be a string like "jdbc:derby:mydb", or "jdbc:derby://localhost:1527/my/db". If you can post that, it will help us give you more information. – Bryan Pendleton Jul 17 '14 at 02:59
  • Hey Bryan, thanks for you're advice. You put me on the right path and I found the location eventually. I greatly appreciate you're feedback. – Liam Quinlan Jul 22 '14 at 11:58

2 Answers2

3

To connect using derby ij command line tool use the following command:

connect 'jdbc:derby://localhost:1527/sun-appserv-samples';

'sun-appserv-samples' is the default Glassfish container managed db name.

As follows;

Oracle documentation on domain.xml file

If you specify that you're database is to be container managed and you are using Glassfish, then all of the database properties can be found in the domain.xml file.

For example, if you are using the default glassfish domain named domain1, then you must navigate to ..glassfish/domains/domain1 on you're file system. The domain.xml file can be found in the config folder.

Here you will find the following information detailing all of you're database properties.

<property name="PortNumber" value="1527"></property>
<property name="Password" value="APP"></property>
<property name="User" value="APP"></property>
<property name="serverName" value="localhost"></property>
<property name="DatabaseName" value="sun-appserv-samples"></property>
<property name="connectionAttributes" value=";create=true"></property>

As you can see the default database name is sun-appserv-samples.

To connect to this database you must open the command tool ij which can be found in you're derby bin folder. Then use the following command to connect to the database.

connect 'jdbc:derby://localhost:1527/sun-appserv-samples';

Note: You must have derby running and you're java web application deployed on Glassfish first.

0

I am not sure you can access directly a derby database that is in-memory.

perbellinio
  • 682
  • 5
  • 14
  • Thanks so much for you're reply. That is a very good point, I never considered that. I will do more research to see if that is the case. Thanks, Liam – Liam Quinlan Jul 16 '14 at 14:00
  • You're welcome. Thank you to vote for my answer if you consider that it is sufficient. – perbellinio Jul 16 '14 at 14:05
  • You should take a look on that article [link](http://www.eclipse.org/articles/article.php?file=Article-EclipseDbWebapps/index.html) – perbellinio Jul 16 '14 at 14:16
  • I could not mark you're answer as useful as I do not have the reputation yet. Thanks again for taking the time to offer an answer. If you agree with my answer i'd greatly appreciate you marking it up as useful. Cheers, Liam – Liam Quinlan Jul 22 '14 at 12:17