cassandra java
parent
fa3c069b00
commit
9e58b702e9
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,32 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.hsma</groupId>
|
||||
<artifactId>cassandra</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cassandra</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cassandra</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<version>4.18.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.9.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,30 @@
|
|||
package org.example;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
import com.datastax.oss.driver.api.core.cql.ResultSet;
|
||||
import com.datastax.oss.driver.api.core.cql.Row;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class QueryApp {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*
|
||||
* @see <a href="https://github.com/datastax/java-driver/tree/4.x/manual/core">Manual</a>
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try (CqlSession session = CqlSession.builder()
|
||||
.addContactPoint(new InetSocketAddress("localhost", 9042)) // = CqlSession.builder().build()
|
||||
.withLocalDatacenter("datacenter1") // benötigt wenn contact point explizit angegeben
|
||||
.withKeyspace("test") // unser keyspace (z.B. use test;)
|
||||
.build()) {
|
||||
ResultSet rs = session.execute("select * from professoren");
|
||||
for (Row row : rs) {
|
||||
System.out.println(row.getString("name"));
|
||||
//System.out.println(row.getFormattedContents());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ public class QueryApp {
|
|||
try (MongoClient mongoClient = MongoClients.create(uri)) {
|
||||
MongoDatabase database = mongoClient.getDatabase("hs"); // TODO database
|
||||
MongoCollection<Document> collection = database.getCollection("professoren"); // TODO collection
|
||||
Document doc = collection.find(eq("Name", "Sokrates")).first();
|
||||
Document doc = collection.find(eq("Name", "Curie")).first();
|
||||
if (doc != null) {
|
||||
System.out.println(doc.toJson());
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue