Apache Derby Network Server
(→Eclipse Data Source Explorer) |
|||
(4 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | This | + | This tutorial shows how to setup the Apache Derby Database as a Network Server and how to configure Eclipse and your JPA project accordingly. |
+ | |||
+ | <pre style="color:red"> | ||
+ | This tutorial is kind of obsolete | ||
+ | </pre> | ||
== Introduction == | == Introduction == | ||
Line 37: | Line 41: | ||
# Select ''Derby'' as Connection Profile Type and enter a meaningful name for the connection, e.g. ''Derby Network Server''. Then proceed to the next page. | # Select ''Derby'' as Connection Profile Type and enter a meaningful name for the connection, e.g. ''Derby Network Server''. Then proceed to the next page. | ||
# If you can select ''Derby Client JDBC Driver'' from the combo-box, do that and skip the next step. Else we will create this driver in the next step. | # If you can select ''Derby Client JDBC Driver'' from the combo-box, do that and skip the next step. Else we will create this driver in the next step. | ||
− | # Click the blue symbol next to the combo-box to create a new driver definition. From the list of driver templates, select ''Derby Client JDBC Driver''. On the tab ''JAR List'', | + | # Click the blue symbol next to the combo-box to create a new driver definition. From the list of driver templates, select ''Derby Client JDBC Driver''. On the tab ''JAR List'', enter the correct path to the <code>lib/derbyclient.jar</code> file inside the directory you have unzipped in the first part of this tutorial. Then click OK. |
# In the ''General'' tab: | # In the ''General'' tab: | ||
## Enter a meaningful name for the database. | ## Enter a meaningful name for the database. | ||
Line 48: | Line 52: | ||
=== Configuring the Persistence Unit === | === Configuring the Persistence Unit === | ||
+ | |||
+ | To use the new connection inside your Java (web) project, the settings for the persistence unit (inside <code>persistence.xml</code>) must also be updated. | ||
+ | |||
+ | # Open the <code>persistence.xml</code> file for your specific project. | ||
+ | # Inside the tab ''Connection'', click ''Populate from connection...'' and select the server you have created before. | ||
+ | # Save the file. | ||
+ | |||
+ | Now, you should be able to program your JPA application as usual, but with the benefit of maintaining multiple connections to one database from different programs. | ||
+ | |||
+ | '''Tip''': Using a ''SQL scrapbook page'' and the ''SQL results'' view, you can easily browse the database from inside Eclipse using SQL queries. |
Latest revision as of 01:48, 28 October 2013
This tutorial shows how to setup the Apache Derby Database as a Network Server and how to configure Eclipse and your JPA project accordingly.
This tutorial is kind of obsolete
Contents |
Introduction
Derby has two operation modes: Embedded and Network Server. Using the former one, only one Java Virtual Machine (JVM) at a time can access the database (if you are reading this tutorial, you probably have come across this issue during the practical software engineering course). The latter one allows more than one JVM, i. e. more than one program at a time to connect to the database using TCP networking. In this way, it is possible to test an application that uses a particular Derby database and at the same time leave the connection in the Eclipse Data Source Explorer open.
Part I: Setup and start the server
The following steps are valid for Windows, Linux and Mac OS X.
Installation
Download and unzip the latest official Derby release (currently db-derby-10.8.2.2-bin.zip
) from http://db.apache.org/derby/derby_downloads.html into a directory of your choice.
Start
The Derby Network Server is started via the command line. First, change to the directory where you have unzipped the file from the previous step.
$ cd path/to/db-derby-10.8.2.2-bin/lib
The actual start command is:
$ java -jar derbyrun.jar server start Tue Nov 22 19:36:54 CET 2011 : Security manager installed using the Basic server security policy. Tue Nov 22 19:36:55 CET 2011 : Apache Derby Network Server - 10.8.2.2 - (1181258) started and ready to accept connections on port 1527
If everything is alright, the server starts and shows a message similar to this one in the command-line window. As you can see, it is listening for incoming connections on port 1527.
Note: You can shutdown the server using the keyboard combination Ctrl-C.
Part II: Configuring Eclipse and your JPA project
Eclipse Data Source Explorer
- Open the Eclipse Data Source Explorer View.
- Right-click Database Connections and select New... to create a new Database Connection Profile.
- Select Derby as Connection Profile Type and enter a meaningful name for the connection, e.g. Derby Network Server. Then proceed to the next page.
- If you can select Derby Client JDBC Driver from the combo-box, do that and skip the next step. Else we will create this driver in the next step.
- Click the blue symbol next to the combo-box to create a new driver definition. From the list of driver templates, select Derby Client JDBC Driver. On the tab JAR List, enter the correct path to the
lib/derbyclient.jar
file inside the directory you have unzipped in the first part of this tutorial. Then click OK. - In the General tab:
- Enter a meaningful name for the database.
- Provide an arbitrary, non-empty username and password for the connection.
- Ensure that the host is
localhost
and the port is1527
. - Ensure that the option Create database (if required) is checked.
- Click on Test Connection to see if the setup is correct. Then click Finish.
As a result, you should see the server as a new entry in the Data Source Explorer view.
Configuring the Persistence Unit
To use the new connection inside your Java (web) project, the settings for the persistence unit (inside persistence.xml
) must also be updated.
- Open the
persistence.xml
file for your specific project. - Inside the tab Connection, click Populate from connection... and select the server you have created before.
- Save the file.
Now, you should be able to program your JPA application as usual, but with the benefit of maintaining multiple connections to one database from different programs.
Tip: Using a SQL scrapbook page and the SQL results view, you can easily browse the database from inside Eclipse using SQL queries.