Skip to content
Snippets Groups Projects
README.md 1.58 KiB
Newer Older
# Working with Picodata using native Java driver

## Requirements

- JDK 8+ (17 and higher is recommended)
- Docker or Podman

## Running this example

1. Clone this repo and build it using the Maven wraper script:

```shell
git clone https://git.picodata.io/picodata/picodata/examples/-/tree/master/picodata-java-example
```

```shell
./mvnw install
```

2. Go to `src/main/resources` directory and run the Docker containers with example Picodata cluster:

```shell
docker-compose up -d
```

3. Set up driver user authorization for Picodata in the container:

```shell
docker-compose exec picodata-1 bash -c "echo -ne \"ALTER USER \\\"admin\\\" WITH PASSWORD 'P@ssw0rd';\" | picodata admin /var/lib/picodata/picodata-1/admin.sock"
```

4. Return to the initial directory `picodata-java-example` and launch the example application.


For JDK 17 and higher:

```shell
_JAVA_OPTIONS="--add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED" ./mvnw exec:java
```

For older JDKs:

```shell
./mvnw exec:java
```

In case of successful run you should see logs like the following in your console:

```
[nioEventLoopGroup-2-1] INFO  i.p.d.c.c.AbstractTarantoolConnectionManager - Connected to Tarantool server at /127.0.0.1:3301
Insert result:
row_count 1
Select all characters after insert:
metadata [{name=id, type=integer}, {name=name, type=string}, {name=year, type=integer}]
rows [[2, Vasya, 2000]]
[io.picodata.PicodataExample.main()] INFO  i.p.d.c.c.AbstractTarantoolConnectionManager - Disconnected from /127.0.0.1:3301

```