Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Scout, PostgreSQL and Docker
Scout, PostgreSQL and Docker [message #1749506] Wed, 07 December 2016 13:56
Matthias Zimmermann is currently offline Matthias ZimmermannFriend
Messages: 208
Registered: June 2015
Senior Member
Goal: Get started with PostgreSQL and Docker in 30'
Prerequisite: Running Scout "Hello World" + running Docker installation, some shell (eg. bash as used in the text below)

Steps to reproduce:

  1. Pull PostgreSQL Docker image
  2. Create Database
  3. Add PostgreSql Service to Scout "Hello World"
  4. Use the PostgreSql service

Disclaimer: This is copy/paste from the thread to connect to MySQL. it only differs in the places that are specific to PostgreSQL.

1. Pull PostgreSQL Docker Image
Command line sequence to pull PostgreSQL image and start PostgreSQL container
docker docker pull postges:latest
docker run --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:latest

After the above commands you have an instance of a PostgreSQL server running in a Docker container.

2. Create Database
Use the running container to add a minimal PostgreSQL datbase named 'my_first_db'
docker exec -it postgres bash

Now start and use the PostgreSQL command line interface (CLI)
psql -U postgres
create database my_first_db;
\c my_first_db
CREATE TABLE example (id SERIAL PRIMARY KEY, value VARCHAR(100), time_created TIMESTAMP(6));
INSERT INTO example (value, time_created) VALUES ('hello world!', current_timestamp);

4. Add PostgreSqlService Service to Scout "Hello World"
There are two points for this step. First, add the necessary Maven dependencies to the pom.xml of the Scout "Hello World" server module.
               <!-- add the two dependencies below -->

Most, likely you have now to update the helloworld.server, the and the projekcts (use Alt+F5 or the corresponding context menu in the Package Explorer)

Then, add the PostgreSqlServiceto the hello world server according to the code shown below:
public class PostgreSqlService extends AbstractPostgreSqlService {
	protected String getConfiguredJdbcMappingName() {
		String host = "<Your Docker IP here>"; // Docker IP as obtained from 'docker-machine ip default'
		return "jdbc:postgresql://" + host + "/my_first_db";
	protected String getConfiguredUsername() {
		return "postgres";
	protected String getConfiguredPassword() {
		return "password";

5. Use the PostgreSqlService Service
This is the simplest step: Just use the new Service in the existing HelloWorldService and restart the hello world server and client app in the Eclipse IDE.

For example:
public class HelloWorldService implements IHelloWorldService {

	public HelloWorldFormData load(HelloWorldFormData input) {
		StringHolder text = new StringHolder();
		SQL.selectInto("SELECT value FROM example WHERE id = 1 INTO :text", new NVPair("text", text));

		StringBuilder msg = new StringBuilder();
		return input;

When the hello world form is opened in the message "hello world!" from the PostgreSQL database is shown in the message field.
Previous Topic:Scout, MySQL and Docker
Next Topic:AbstractPage(WithTable) ans SearchForms
Goto Forum:

Current Time: Thu Oct 01 05:36:18 GMT 2020

Powered by FUDForum. Page generated in 0.01404 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top