cassandra beispiel
parent
460dafa69e
commit
dba3977c7e
|
@ -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>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<version>4.15.0</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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ public class QueryApp {
|
|||
// Replace the placeholder with your MongoDB deployment's connection string
|
||||
String uri = "mongodb://localhost:27017";
|
||||
try (MongoClient mongoClient = MongoClients.create(uri)) {
|
||||
MongoDatabase database = mongoClient.getDatabase("mytest");
|
||||
MongoDatabase database = mongoClient.getDatabase("hs");
|
||||
MongoCollection<Document> collection = database.getCollection("professoren");
|
||||
Document doc = collection.find(eq("Name", "Sokrates")).first();
|
||||
if (doc != null) {
|
||||
|
|
Loading…
Reference in New Issue