I need to make a presentation + connection to Cassandra for class. The fact is that it does not let me connect when I use the datastax drivers. I have gone a thousand times because apparently there are old versions that are incompatible and well, I lost a few hours with this.
My code now looks like this:
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
public class conectaradb {
public static void main(String[] args) {
try {
Cluster cluster;
Session sesion;
cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(9042).build();
sesion= cluster.connect("ejemplodb");
ResultSet resultado= sesion.execute("select * from empleados");
String nombreemp,fecha,cargo;
double comision,salario;
int empno;
for (Row row:resultado) {
empno=row.getInt("empno");
cargo=row.getString("cargo");
comision=row.getDouble("comision");
fecha=row.getString("fechaing");
nombreemp=row.getString("nombreempno");
salario=row.getDouble("salario");
System.out.println(empno+" "+cargo+" "+comision+" "+fecha+" "+nombreemp+" "+salario);
}
cluster.close();
}catch(NoHostAvailableException e) {
System.out.println(e.getErrors());
}
}
}
The error appears when connecting to localhost ... I have also been fussing with the .yaml file, so if anyone knows the correct configuration they should have, it would be great.