Cassandra (二)Java | scala操作
<Java>
1、pom
<dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-core</artifactId> <version>3.1.1</version> </dependency>
2、代码
PoolingOptions pool = new PoolingOptions(); pool.setMaxRequestsPerConnection(HostDistance.LOCAL,32); pool.setCoreConnectionsPerHost(HostDistance.LOCAL,2) .setMaxConnectionsPerHost(HostDistance.LOCAL,4) .setCoreConnectionsPerHost(HostDistance.REMOTE,2) .setMaxConnectionsPerHost(HostDistance.REMOTE,4); Cluster clst = Cluster.builder().addContactPoint("192.168.133.195").withPort(9042) .withCredentials("cassandra", "cassandra").build(); Session session = clst.connect(); //查询数据 String sql="select * from mydemo.userinfos"; ResultSet res = session.execute(sql); for(Row row:res){ System.out.println(row.getInt("userid")+":"+row.getDate("bir") +":"+row.getInt("sex")+":"+row.getString("username")); }
<scala>