Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial #486

Open
landongyu opened this issue Apr 2, 2024 · 1 comment
Open

Tutorial #486

landongyu opened this issue Apr 2, 2024 · 1 comment
Labels
C-enhancement Category: An issue proposing an enhancement

Comments

@landongyu
Copy link

Affected Areas

Something else (please specify in the description!)

Feature Description

Polypheny Tutorial

# Polypheny Tutorial.md

Use Case(s)

No response

Possible Solutions

No response

Possible Alternatives

No response

@landongyu landongyu added the C-enhancement Category: An issue proposing an enhancement label Apr 2, 2024
@landongyu
Copy link
Author

Polypheny Tutorial

                                                       

0.Introduction

Polypheny is an open source and powerful database with easy-to-use, scalable, and flexible data storage architecture. A key characteristic and unique feature of Polypheny is its ability to seamlessly map between different data models. A key characteristic and unique feature of Polypheny is its ability to seamlessly map between different data models. This enables all data to be queried using all supported query languages - independent of the data model the query language is used. independent of the data model the query language is based on.This will simplify the work of programmers. This tutorial will help you understand the design, working principles and basic usage of polypheny database. This tutorial is based on Windows operating system and Java language.

1.Download and install polypheny

Polypheny supports several operating systems, including Linux, Windows and Mac OS X. Before we start learning polypheny, we need to install polypheny first. Here we take Windows as an example:

Click on the download link below: https://github.com/polypheny/Polypheny-DB/releases/tag/v0.9.1

We can see that polypheny offers several installation packages for your system, you can download them as needed.

Once downloaded we click on the installer to start the installation. If you need to change the installation folder, please select the installation location, otherwise just click next and then click install.

You can find polypheny on your desktop after installation.

2.Start polypheny

Double click to open polypheny, the first startup will do some initialization, it may be slow, please be patient.

The console page will be opened automatically after successful startup. Default address:(http://localhost:8080/#/views/monitoring)

Polypheny's Query Interface for drivers and connectors will occupy port: 20591. Please make sure this port is available, or go to the configuration file to change the default port.

3.Using the Visual Console

The web UI console makes polypheny much easier to use, it no longer requires a visual database connection tool. All your configuration changes, server status, load monitoring, and basic data additions, deletions, and modifications can be done through this webUI.

3.1Load Monitoring

You can clearly see the load of your business operations on the home page for real-time server monitoring and adjustment.

3.2Creating Namespaces and Tables

Polypheny separates tables for different businesses through namespaces, similar to other relational databases' databases. polypheny is powerful in that its namespaces support relational, document, and graph.

After creating the namespace, you can click into the namespace to build a table. Everything is visualized and you don't even need to write any SQL statements.

3.3Add, delete, update and select data

Click on data, we can see the specific data in the table.

Clicking on query, we can get a window to write sql statement to manipulate the data.

3.4Settings
3.4.1You can go through the ui interface to set the port, very convenient.

3.4.2You can set the relevant thread parameters of polypheny

3.4.3Partition Settings

There are other settings, which are not described here, waiting for your exploration.

4.Integration of polypheny in the project (base on Java & JDBC)

Like other databases, polypheny supports connectivity via a JDBC driver. it provides a standard interface for executing SQL queries, retrieving results, and managing database connections.

4.1Building a Java Project

Here's a maven project using Idea to go to build so that you can better manage dependencies.

Ensure that your local JDK version and the choice of the same, there is no need to pursue a high version of the JDK.

The pom file configuration, you need to introduce polypheny-jdbc-driver dependency.

Create a new application class file, the name here can be arbitrary, there needs to be a main function in it.

4.2Connection Code

The following is the complete code, where jdbcurl is pointing to your local polypheny, if your port number is not changed then this parameter does not need to be changed, username is defaulted to 'pa' and password is defaulted to "".

public static void main( String[] args ) {
    String jdbcUrl = "jdbc:polypheny://localhost:20591";
    String username = "pa";
    String password = "";
    try {
        // Load the JDBC driver class
        try {
            Class.forName( "org.polypheny.jdbc.Driver" );
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        // Establish a connection to the Polypheny database
        Connection connection = DriverManager.getConnection( jdbcUrl, username, password );

        // Create a statement for executing SQL queries
        Statement statement = connection.createStatement();

        // Execute an SQL query
        String sql = "SELECT * FROM emp";
        ResultSet resultSet = statement.executeQuery( sql );

        // Process the query results
        while (resultSet.next()) {
            // Retrieve data from the result set
            int id = resultSet.getInt( "employeeno" );
            String age = resultSet.getString( "age" );
            String gender = resultSet.getString( "gender" );
            String workingyears = resultSet.getString( "workingyears" );
            String relationshipjoy = resultSet.getString( "relationshipjoy" );
            // ...

            // Do something with the data
            System.out.println( "employeeno: " + id + ", age: " + age + ", gender: "
                    + gender+ ", workingyears: " + workingyears+ ", relationshipjoy: " + relationshipjoy);
        }

        // Close the result set, statement, and connection
        resultSet.close();
        statement.close();
        connection.close();
    } catch ( SQLException e ) {
        e.printStackTrace();
    }
}

The code establishes a JDBC connection and queries the emp table for all the data, then takes out the employeeno, age, etc. fields from it.

Through the console printout we see that the data can be queried normally, so we have successfully connected to the polypheny database. This concludes the tutorial on polypheny.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement
Projects
None yet
Development

No branches or pull requests

1 participant