Search code examples
cassandradatastaxdatastax-java-driver

Error java.net.UnknownHostException while connecting Cassandra cluster


I am doing a PoC to connect Cassandra from my java8 application code. I am using apache Cassandra with java8

To start with I looked and started with https://github.com/lankydan/datastax-java-driver

Trying to connect my Cassandra cluster

when i download and try to connect the same to my C* cluster I am getting Caused by: java.net.UnknownHostException: 10.24.78.22,10.24.78.108,10.24.79.173

Updated **CassandraConfig**
.addContactPoints(host)

I updated **application.properties** file
cassandra.host=10.24.78.22,10.24.78.108,10.24.79.173
cassandra.cluster.name=My_Cluster
cassandra.port=9042
cassandra.keyspace=rrr_xxx

So what need to be fixed, and how to fix this issue?


Solution

  • the .addContactPoints function accepts an array of the strings, inet addresses, hosts, etc., while you're passing a one string with multiple addresses inside. You need somehow convert this string into array, or pass only one address.

    if you already modifying the code, then it should be simply changed to

    .addContactPoints(host.split(","))