最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Authentication for CrateDB SU crate failed using CrateDB 5.10.3 with JDBC Driver - Stack Overflow

programmeradmin2浏览0评论

I'm trying to connect my CrateDB (running locally) with Java using JDBC.

public class Main {

    private static String connectionURL = "jdbc:postgresql://localhost:5432/";

    public static void main(String[] args) throws SQLException {

        Properties props = new Properties();
        props.setProperty("user", "crate");

        Connection sqlConnection = DriverManager.getConnection(connectionURL, props);

        if(!sqlConnection.isClosed()) {
            System.out.println("Connection is open!");
        } else {
            System.out.println("Connection is closed!");
        }
    }
}

Dependencies I'm using for this project:

    <dependencies>

        <dependency>
            <groupId>.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>LATEST</version>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.82</version>
        </dependency>

    </dependencies>

This is my current Main Class and its simple enough. The CrateDB SU does not have a Password (as said in the documentation) and shouldn't require one according to my auth settings in the crate.yml:d

auth:
  host_based:
    enabled: true
    config:
      0:
        user: crate
        address: _local_
        method: trust
      99:
        method: password

Yet when i try to run my Main Method i get the following error:

Exception in thread "main" .postgresql.util.PSQLException: The server requested SCRAM-based authentication, but no password was provided.
    at .postgresql.core.v3.ConnectionFactoryImpl.lambda$doAuthentication$5(ConnectionFactoryImpl.java:848)
    at .postgresql.core.v3.AuthenticationPluginManager.withPassword(AuthenticationPluginManager.java:82)
    at .postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:845)
    at .postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:213)
    at .postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:268)
    at .postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54)
    at .postgresql.jdbc.PgConnection.<init>(PgConnection.java:273)
    at .postgresql.Driver.makeConnection(Driver.java:446)
    at .postgresql.Driver.connect(Driver.java:298)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:191)
    at src.main.java.XXXX.Main.main(Main.java:17)

If I add a Password Property, i also get the error that the SU password is empty and that authentification has failed. (And it is not possible to set a password for the CrateDB Superuser)

I tried adding a new User (Admin) and giving it a password as well as giving it all Priviliges but this fails also.

I have also tried using a different driver:

    <dependencies>

        <dependency>
            <groupId>io.crate</groupId>
            <artifactId>crate-jdbc</artifactId>
            <version>2.7.0</version>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.82</version>
        </dependency>

    </dependencies>

But i get a error which is even weirder:

public class Main {

    private static String connectionURL = "jdbc:crate://localhost:5432/";

    public static void main(String[] args) throws SQLException {

        Properties props = new Properties();
        props.setProperty("user", "crate");

        Connection sqlConnection = DriverManager.getConnection(connectionURL, props);

        if(!sqlConnection.isClosed()) {
            System.out.println("Connection is open!");
        } else {
            System.out.println("Connection is closed!");
        }
    }
}

The Error i get:

Exception in thread "main" io.crate.shade.postgresql.util.PSQLException: Etwas Ungewöhnliches ist passiert, das den Treiber fehlschlagen ließ. Bitte teilen Sie diesen Fehler mit.
    at io.crate.shade.postgresql.Driver.connect(Driver.java:265)
    at io.crate.client.jdbc.CrateDriver.connect(CrateDriver.java:65)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:191)
    at src.main.java.XXXX.Main.main(Main.java:17)
Caused by: java.lang.IllegalArgumentException: Null value for 'password'
    at com.ongres.scrammon.util.Preconditions.checkNotNull(Preconditions.java:41)
    at com.ongres.scrammon.util.Preconditions.checkNotEmpty(Preconditions.java:55)
    at com.ongres.scram.client.ScramSession$ServerFirstProcessor.clientFinalProcessor(ScramSession.java:130)
    at io.crate.shade.postgresql.jre8.sasl.ScramAuthenticator.processServerFirstMessage(ScramAuthenticator.java:131)
    at io.crate.shade.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:663)
    at io.crate.shade.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141)
    at io.crate.shade.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
    at io.crate.shade.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at io.crate.shade.postgresql.jdbc.PgConnection.<init>(PgConnection.java:206)
    at io.crate.shade.postgresql.Driver.makeConnection(Driver.java:442)
    at io.crate.shade.postgresql.Driver.connect(Driver.java:244)
    ... 4 more

So i would like to stick to the PostgreSQL driver instead of the crate.io Driver provided.

I have tried to google but i simply cannot find anything (or im blind) so any help would be appreciated.

I tried to get a JDBC Connection running with my Java-Project and expected a simple "Connection is open!" from my program so i know my Java-Code connects with Crates JDBC driver.

I'm trying to connect my CrateDB (running locally) with Java using JDBC.

public class Main {

    private static String connectionURL = "jdbc:postgresql://localhost:5432/";

    public static void main(String[] args) throws SQLException {

        Properties props = new Properties();
        props.setProperty("user", "crate");

        Connection sqlConnection = DriverManager.getConnection(connectionURL, props);

        if(!sqlConnection.isClosed()) {
            System.out.println("Connection is open!");
        } else {
            System.out.println("Connection is closed!");
        }
    }
}

Dependencies I'm using for this project:

    <dependencies>

        <dependency>
            <groupId>.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>LATEST</version>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.82</version>
        </dependency>

    </dependencies>

This is my current Main Class and its simple enough. The CrateDB SU does not have a Password (as said in the documentation) and shouldn't require one according to my auth settings in the crate.yml:d

auth:
  host_based:
    enabled: true
    config:
      0:
        user: crate
        address: _local_
        method: trust
      99:
        method: password

Yet when i try to run my Main Method i get the following error:

Exception in thread "main" .postgresql.util.PSQLException: The server requested SCRAM-based authentication, but no password was provided.
    at .postgresql.core.v3.ConnectionFactoryImpl.lambda$doAuthentication$5(ConnectionFactoryImpl.java:848)
    at .postgresql.core.v3.AuthenticationPluginManager.withPassword(AuthenticationPluginManager.java:82)
    at .postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:845)
    at .postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:213)
    at .postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:268)
    at .postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54)
    at .postgresql.jdbc.PgConnection.<init>(PgConnection.java:273)
    at .postgresql.Driver.makeConnection(Driver.java:446)
    at .postgresql.Driver.connect(Driver.java:298)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:191)
    at src.main.java.XXXX.Main.main(Main.java:17)

If I add a Password Property, i also get the error that the SU password is empty and that authentification has failed. (And it is not possible to set a password for the CrateDB Superuser)

I tried adding a new User (Admin) and giving it a password as well as giving it all Priviliges but this fails also.

I have also tried using a different driver:

    <dependencies>

        <dependency>
            <groupId>io.crate</groupId>
            <artifactId>crate-jdbc</artifactId>
            <version>2.7.0</version>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.82</version>
        </dependency>

    </dependencies>

But i get a error which is even weirder:

public class Main {

    private static String connectionURL = "jdbc:crate://localhost:5432/";

    public static void main(String[] args) throws SQLException {

        Properties props = new Properties();
        props.setProperty("user", "crate");

        Connection sqlConnection = DriverManager.getConnection(connectionURL, props);

        if(!sqlConnection.isClosed()) {
            System.out.println("Connection is open!");
        } else {
            System.out.println("Connection is closed!");
        }
    }
}

The Error i get:

Exception in thread "main" io.crate.shade..postgresql.util.PSQLException: Etwas Ungewöhnliches ist passiert, das den Treiber fehlschlagen ließ. Bitte teilen Sie diesen Fehler mit.
    at io.crate.shade..postgresql.Driver.connect(Driver.java:265)
    at io.crate.client.jdbc.CrateDriver.connect(CrateDriver.java:65)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:191)
    at src.main.java.XXXX.Main.main(Main.java:17)
Caused by: java.lang.IllegalArgumentException: Null value for 'password'
    at com.ongres.scrammon.util.Preconditions.checkNotNull(Preconditions.java:41)
    at com.ongres.scrammon.util.Preconditions.checkNotEmpty(Preconditions.java:55)
    at com.ongres.scram.client.ScramSession$ServerFirstProcessor.clientFinalProcessor(ScramSession.java:130)
    at io.crate.shade..postgresql.jre8.sasl.ScramAuthenticator.processServerFirstMessage(ScramAuthenticator.java:131)
    at io.crate.shade..postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:663)
    at io.crate.shade..postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141)
    at io.crate.shade..postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
    at io.crate.shade..postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at io.crate.shade..postgresql.jdbc.PgConnection.<init>(PgConnection.java:206)
    at io.crate.shade..postgresql.Driver.makeConnection(Driver.java:442)
    at io.crate.shade..postgresql.Driver.connect(Driver.java:244)
    ... 4 more

So i would like to stick to the PostgreSQL driver instead of the crate.io Driver provided.

I have tried to google but i simply cannot find anything (or im blind) so any help would be appreciated.

I tried to get a JDBC Connection running with my Java-Project and expected a simple "Connection is open!" from my program so i know my Java-Code connects with Crates JDBC driver.

Share Improve this question asked Mar 31 at 10:00 LucaLuca 113 bronze badges New contributor Luca is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 3
  • Still I would try the second case trying with a password. Use getConnection(String url, String user, String password) with password "". – Joop Eggen Commented Mar 31 at 10:22
  • Why are trying with a postesql jdbc driver instead of the specific driver in the first place? – aled Commented Mar 31 at 13:47
  • Because when i use the Crate.io jdbc driver does not work and i cannot find anything to help me fix this error (see the bottom of my post) I either get a weird error, saying that "Something uncommon happened" or that the Role for the Superuser crate doesn't exist. I have already switched back to the crateDB driver ( <dependency> <groupId>io.crate</groupId> <artifactId>crate-jdbc</artifactId> <version>2.6.0</version> </dependency> ) But it still doesn't work. – Luca Commented Apr 1 at 0:58
Add a comment  | 

1 Answer 1

Reset to default 0

After looking through the Internet for what felt like a whole lifetime i stumbled onto a Github Issue for CrateDB and changed the port used by CrateDB to 5433 because PostgreSQL is installed and is using Port 5432.

发布评论

评论列表(0)

  1. 暂无评论