Querying Polypheny From Java

The Polypheny JDBC driver allows Java applications to connect and interact with the Polypheny database system. It provides a standard interface for executing SQL queries, retrieving results, and managing database connections.

This documentation will guide you through the installation process for Maven and Gradle, and provide examples of how to use the Polypheny JDBC driver in your Java applications.

Installation

Maven

To use the Polypheny JDBC driver in a Maven project, you need to add the driver as a dependency in your project’s pom.xml file:

<dependencies>
    <dependency>
        <groupId>org.polypheny</groupId>
        <artifactId>polypheny-jdbc-driver</artifactId>
        <version>1.5.3</version>
    </dependency>
</dependencies>

After adding the dependency, you can build your project with Maven, and the Polypheny JDBC driver will be automatically downloaded and included in your project’s classpath.

Gradle

To use the Polypheny JDBC driver in a Gradle project, you need to add the driver as a dependency in your project’s build.gradle file:

dependencies {
    implementation 'org.polypheny:polypheny-jdbc-driver:1.5.3'
}

After adding the dependency, you can build your project with Gradle, and the Polypheny JDBC driver will be automatically downloaded and included in your project’s classpath.

The version number is for illustration purposes only. Please always check on Maven Central for the latest version.

Usage

To use the Polypheny JDBC driver in your Java application, you need to follow these steps:

  1. Load the JDBC driver class.
  2. Establish a connection to the Polypheny database.
  3. Create a statement for executing SQL queries.
  4. Execute SQL queries and retrieve results.
  5. Close the connection and release resources.

Here is an example of using the Polypheny JDBC driver to execute a simple SQL query:

import java.sql.*;

public class PolyphenyExample {

    public static void main( String[] args ) {
        String jdbcUrl = "jdbc:polypheny://localhost/";
        String username = "pa";
        String password = "";

        try {
            // Load the JDBC driver class
            Class.forName( "org.polypheny.jdbc.Driver" );

            // 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 mytable";
            ResultSet resultSet = statement.executeQuery( sql );

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

                // Do something with the data
                System.out.println( "ID: " + id + ", Name: " + name );
            }

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

Make sure to replace jdbc:polypheny://localhost:5432/mydatabase with the actual JDBC URL of your Polypheny database, and myuser and mypassword with the appropriate credentials.

That’s it! You can now use the Polypheny JDBC driver to connect to and interact with your Polypheny database in your Java applications.

Conclusion

This documentation provided installation instructions for Maven and Gradle, and examples of how to use the Poly

© Polypheny GmbH. All Rights Reserved.