0

I use JDBC to connect to CnosDB according to the official website documentation.

It seems that I can't compile the project.

Here is my project structure:

├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── org
    │   │       └── example
    │   │           └── Main.java
    │   └── resources
    └── test
        └── java

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>arrow-flight-jdbc</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-jdbc -->
    <dependencies>
        <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>arrow-jdbc</artifactId>
            <version>11.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.arrow/flight-sql-jdbc-driver -->
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>flight-sql-jdbc-driver</artifactId>
            <version>11.0.0</version>
        </dependency>
    </dependencies>
</project>

Main.java

package org.example;

import java.sql.*;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {
        final Properties properties = new Properties();
        properties.put("user", "root");
        properties.put("password", "");
        properties.put("tenant", "cnosdb");
        properties.put("useEncryption", false);
        properties.put("database", "public");
        try (
                Connection connection = DriverManager.getConnection(
                "jdbc:arrow-flight-sql://127.0.0.1:8904", properties
                );
                Statement statement = connection.createStatement())
        {
            statement.execute("CREATE TABLE IF NOT EXISTS air\n" +
                    "(\n" +
                    "    visibility  DOUBLE,\n" +
                    "    temperature DOUBLE,\n" +
                    "    pressure    DOUBLE,\n" +
                    "    TAGS(station)\n" +
                    ");");
            statement.executeUpdate("INSERT INTO air (time, station, visibility, temperature, pressure) VALUES\n" +
                    "    (1666165200290401000, 'XiaoMaiDao', 56, 69, 77);");
            ResultSet resultSet = statement.executeQuery("select * from air limit 1;");

            while (resultSet.next()) {
                Timestamp column1 = resultSet.getTimestamp(1);
                String column2 = resultSet.getString(2);
                Double column3 = resultSet.getDouble(3);
                Double column4 = resultSet.getDouble(4);
                Double column5 = resultSet.getDouble(5);
                System.out.printf("%s %s %f %f %f\n", column1, column2, column3, column4, column5);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

I try to run the following command

_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn exec:java -Dexec.mainClass="org.example.Main"

But throws the following error

[WARNING] java.lang.ClassNotFoundException: org.example.Main at org.codehaus.mojo.exec.URLClassLoaderBuilder$ExecJavaClassLoader.loadClass (URLClassLoaderBuilder.java:198) at java.lang.ClassLoader.loadClass (ClassLoader.java:521) at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:271) at java.lang.Thread.run (Thread.java:1623) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.557 s [INFO] Finished at: 2023-07-07T10:08:51+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project arrow-flight-jdbc: An exception occurred while executing the Java class. org.example.Main -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

How can I connect to CnosDB?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ZuoTiJia
  • 161
  • 5
  • Please see https://stackoverflow.com/questions/17408769/how-do-i-resolve-classnotfoundexception – cosmic Jul 07 '23 at 03:08

0 Answers0