can somebody help and answer me, why I can not connect and get an error in netbeans. I get the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.datastax.driver.core.Cluster.(Cluster.java:63) at testcassandra.TestCassandra.main(TestCassandra.java:30) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 2 more
(with Datstax DevCenter I can connect)
Error at cluster = Cluster.builder().addContactPoint("localhost").withPort(9042).build();
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
public class TestCassandra {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Cluster cluster;
Session session;
// Connect to the cluster and keyspace "demo"
cluster = Cluster.builder().addContactPoint("localhost").withPort(9042).build();
session = cluster.connect("demo");
// Insert one record into the users table
session.execute("INSERT INTO users (lastname, age, city, email, firstname) VALUES ('Jones', 35, 'Austin', '[email protected]', 'Bob')");
// Use select to get the user we just entered
ResultSet results = session.execute("SELECT * FROM users WHERE lastname='Jones'");
for (Row row : results) {
System.out.format("%s %d\n", row.getString("firstname"), row.getInt("age"));
}
cluster.close();
}
}