HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:cassandra://localhost:9042/your_keyspace"); config.setUsername("your_username"); config.setPassword("your_password"); HikariDataSource dataSource = new HikariDataSource(config); Connection connection = dataSource.getConnection(); Session session = cluster.connect("your_keyspace"); BatchStatement batch = new BatchStatement(); batch.add(new SimpleStatement("INSERT INTO your_table (id, name) VALUES (?, ?)", 1, "John")); batch.add(new SimpleStatement("INSERT INTO your_table (id, name) VALUES (?, ?)", 2, "Jane")); batch.add(new SimpleStatement("INSERT INTO your_table (id, name) VALUES (?, ?)", 3, "Mike")); session.execute(batch); Session session = cluster.connect("your_keyspace"); AsyncResultSetFuture future = session.executeAsync(new SimpleStatement("SELECT * FROM your_table")); future.thenAccept(resultSet -> { ResultSetRows resultRows = resultSet.currentPage(); });


上一篇:
下一篇:
切换中文