Java with Cassandra connection problem

2,791 views
Skip to first unread message

t.ramesh Kumar

unread,
Apr 8, 2016, 10:32:06 AM4/8/16
to DataStax Java Driver for Apache Cassandra User Mailing List
log4j:WARN No appenders could be found for logger (com.datastax.driver.core.Cluster).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (com.datastax.driver.core.TransportException: [/127.0.0.1:9042] Cannot connect))
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1104)
at com.datastax.driver.core.Cluster.init(Cluster.java:121)
at com.datastax.driver.core.Cluster.connect(Cluster.java:198)
at com.datastax.driver.core.Cluster.connect(Cluster.java:226)
at sample1.sample.main(sample.java:19)


on vmware installed cassandra 3.4 on ubuntu 14.04 .It's working fine with putty and able to create tables,get the data.But getting problem as above i mentioned..

Any Help Appreciated.. 

This is my class



public class sample {

public static void main(String[] args) {
Cluster cluster;
Session session;

   cluster = Cluster.builder().addContactPoint("127.0.0.1").build();


session = cluster.connect("demo");
ResultSet results = session.execute("SELECT * FROM test WHERE id=1");
for (Row row : results) {
System.out.format("%s %d\n", row.getString("name"), row.getInt("id"));
cluster.close();

}
}
}


Markus Geiß

unread,
Apr 8, 2016, 10:33:54 AM4/8/16
to java-dri...@lists.datastax.com
Hey,

maybe a silly point, but did you make sure that calls to the local loopback device (127.0.0.1) are correctly forwarded to your VM?

Best wishes,

Markus Geiss
Chief Architect
RɅĐɅЯ, The Mifos Initiative

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

t.ramesh Kumar

unread,
Apr 8, 2016, 10:43:02 AM4/8/16
to DataStax Java Driver for Apache Cassandra User Mailing List
i attached my putty connect to remote cassandra..

I need to use it in java class ..How to connect cassandra in ubuntu remote from windows java with eclipse..
any help .appreciated.
2.png

Markus Geiß

unread,
Apr 8, 2016, 10:54:48 AM4/8/16
to java-dri...@lists.datastax.com
If I understand you correctly, you've installed Ubuntu and Cassandra on a virtual machine using VMWare.
You use putty to ssh into the virtual machine and then you are able to connect to cassandra using localhost.

If you want to access Cassandra running in the VM you need to map the port used by cassandra to the exposed VM IP, and this IP needs to be used for connecting Cassandra from your host machine.

Best wishes,

Markus Geiss
Chief Architect
RɅĐɅЯ, The Mifos Initiative

t.ramesh Kumar

unread,
Apr 8, 2016, 11:17:57 AM4/8/16
to DataStax Java Driver for Apache Cassandra User Mailing List


Yes,You are Right !

this is my class,and my port and host of cassandra   127.0.0.1:9042

and host 192.168.34.101 of vm

please can let me know how to configuare in java class 

Markus Geiß

unread,
Apr 8, 2016, 11:19:50 AM4/8/16
to java-dri...@lists.datastax.com
you can try to use the IP address the VM is using (the one you may also use for putty) instead of 127.0.0.1 ... just make sure the port 9042 is available via the VMs IP

Best wishes,

Markus Geiss
Chief Architect
RɅĐɅЯ, The Mifos Initiative

t.ramesh Kumar

unread,
Apr 8, 2016, 11:37:34 AM4/8/16
to DataStax Java Driver for Apache Cassandra User Mailing List



Sir,   

 cluster = Cluster.builder().addContactPoint(" 192.168.34.101").build();


result like

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.64.133:9042 (com.datastax.driver.core.TransportException: [/192.168.34.101:9042] Cannot connect))

when i mention like 
 cluster = Cluster.builder().addContactPoint(" 192.168.34.101:9042").build();

result like
invalid IPv6 address

can you please let me know how to include in class the host of vm ip and port..?to cassandra database.

Markus Geiß

unread,
Apr 8, 2016, 11:48:32 AM4/8/16
to java-dri...@lists.datastax.com
I'm not sure how to confiuger your VM correctly ... maybe this is of some help ...


If not simply google it. ; o)

Best wishes,

Markus Geiss
Chief Architect
RɅĐɅЯ, The Mifos Initiative

t.ramesh Kumar

unread,
Apr 8, 2016, 12:26:07 PM4/8/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi All,
          My VM ware working fine,Connected using putty operation are working fine on cassandra.


What exactly i need to connect java class and curd operations on cassandra.But it can't..any help?

Alex Popescu

unread,
Apr 8, 2016, 12:35:49 PM4/8/16
to java-dri...@lists.datastax.com
Markus's reply above:

"If you want to access Cassandra running in the VM you need to map the port used by cassandra to the exposed VM IP, and this IP needs to be used for connecting Cassandra from your host machine."

Basically right now your vm is not allowing external connections to the port 9042 from the host os.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.



--
Bests,

Alex Popescu | @al3xandru
Sen. Product Manager @ DataStax

» DataStax Enterprise - the database for cloud applications. «

t.ramesh Kumar

unread,
Apr 9, 2016, 1:39:46 PM4/9/16
to DataStax Java Driver for Apache Cassandra User Mailing List

I changed the rpc_address and localhost(the one have used for the ssh connection),start_rpc: false ,rpc_port: 9160

All changes on Cassandra.yaml ,after all, changes restarted nodes as $CCM STOP...CCM START Still have Same as above mentioned Problem.Please let me know Any one how to connect Vmware Cassandra from eclipse local.Mean How to configure the ports and host in class.

It's Great Help !
Reply all
Reply to author
Forward
0 new messages