In This Chapter
Almost all Servoy applications utilize a database to store user data and application metadata. Servoy can connect to any database that has a JDBC driver available. Servoy bundles PostgreSQL by default, but PostgreSQL can be removed and replaced by any database management system (DBMS).
Creating a New Database in PostgreSQL
In Servoy Developer, a new PostgreSQL database can be created from the Solution Explorer tree.
- In the Servoy Developer Solution Explorer tab, expand the Database Servers node (under Resources) and right click on any PostgreSQL database (all the example databases provided by Servoy are PostgreSQL) to show the popup menu.
- Select Create PostGreSQL Database.
- Enter a name for the database in the dialog window.
- A dialog will appear as the database is being created.
- Another dialog will alert that the creation is finished.
Connecting to an Existing Database
From within Servoy Develop connections to existing databases can also be setup:
- Determine the JDBC driver required for making connections to the database. The proper driver can normally be determined from the DBMS manufacturer/documentation; another source that may help is the Servoy Forum as other developers have possibly used the database with Servoy.
- Install the driver by placing the .jar file in the
application_server/drivers folder in the Servoy installation folder.
- Restart Servoy Developer.
Create a new Database Server connection by right clicking on Database Servers node (under Resources) and selecting New Server. A submenu will provide choices of different popular database choices that will fill in some of the connection information to make setup easier.
Even though a database is listed here, the JDBC driver must still be installed in the drivers folder in order to connect to the database.
Fill in the Server Name, User Name, Password, URL, and Driver for the database. The correct values for the URL and Driver should be obtained from the database documentation, or suggested values will be already entered when going through the New Server menu.
The user account should be of administrator level as to have full access to database objects in Servoy.
- Save the tab by clicking the save button in the toolbar or using Ctrl-S to save the tab.
- The database should now appear in the Database Servers list.
Creating Tables and Columns
It is best practice to create the data model (tables, primary keys, foreign keys, and fields) before starting to create a solution.Objects in the database can be created with database tools built to administer the database, or within Servoy Developer.
To create a table in Servoy Developer:
- Right click on the database name in the Database Servers node and select Create Table OR With the database name selected, click on the create table button in toolbar of the list view in Solution Explorer.
- A dialog will ask for the name for a new table. Enter a preferred name.
The table editor view will appear allowing new columns to be entered.
When a new table is created, Servoy will add a column in the table editor for the primary key. All tables used in Servoy must have a primary key or a row identifier.
To create columns in Servoy Developer:
- Open the table editor by selecting the database server in the Solution Explorer and doing one of the following in the list view:
- Double clicking on the table name.
- Right clicking on the table name and selecting Edit table/view.
- Select the table and click on the edit table button in the list view toolbar.
- The table editor will appear allowing editing of the columns for the table.
- To add a column, click on the Add button. Change the name from 'type here' to the desired name, the column type, and size (if applicable). Be sure to save when finished.
- To remove a column, click on the Remove button.
Quick Start Video