【问题标题】:Accesing Cassandra Database which uses 'PasswordAuthenticator' in Java访问在 Java 中使用“PasswordAuthenticator”的 Cassandra 数据库
【发布时间】:2015-04-11 00:53:25
【问题描述】:

我在 cassandra.yaml 文件中将 Cassandra 数据库的身份验证器值更改为“PasswordAuthenticator”。 以前我使用以下代码使用 java 连接到数据库。

public void connect(String node) {
      cluster = Cluster.builder()
            .addContactPoint(node).build();
      Metadata metadata = cluster.getMetadata();
      System.out.printf("Connected to cluster: %s\n", 
            metadata.getClusterName());
      for ( Host host : metadata.getAllHosts() ) {
         System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
               host.getDatacenter(), host.getAddress(), host.getRack());
      }
      session = cluster.connect();
   }

现在这段代码给了我错误提示

Exception in thread "main" com.datastax.driver.core.exceptions.AuthenticationException: Authentication error on host /127.0.0.1: Host /127.0.0.1 requires authentication, but no authenticator found in Cluster configuration

我了解我需要使用我的超级用户用户名和密码连接到数据库。使用 java 连接数据库时如何提供这些详细信息?

【问题讨论】:

    标签: java cassandra datastax-java-driver


    【解决方案1】:

    您可以通过将.withCredentials 方法添加到您的集群构建器来做到这一点,如下所示:

      cluster = Cluster.builder()
            .addContactPoint(node)
            .withCredentials("yourusername", "yourpassword")
            .build();
    

    【讨论】:

      猜你喜欢
      • 2013-08-10
      • 2017-05-21
      • 2015-02-20
      • 1970-01-01
      • 2021-10-24
      • 2014-12-16
      • 2019-03-05
      • 2016-10-07
      • 2018-08-03
      相关资源
      最近更新 更多