Cha*_*hna 9 java resultset biginteger cassandra datastax
我正在尝试获取Cassandra列族中的键值对的数量.以下是我使用的代码.
PreparedStatement statement = client.session
.prepare("select count(*) from corpus.word_usage");
ResultSet results = client.session.execute(statement.bind());
Row row = results.one();
System.out.println(row.getVarint(0));
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,我遇到了异常.
Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: Column count is of type bigint
at com.datastax.driver.core.ColumnDefinitions.checkType(ColumnDefinitions.java:291)
at com.datastax.driver.core.ArrayBackedRow.getVarint(ArrayBackedRow.java:185)
at SimpleClient.main(SimpleClient.java:57)
Run Code Online (Sandbox Code Playgroud)
根据datastax文档(http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Row.html),getVarint应该返回一个BigInteger.那么为什么我在这里得到例外?我做错了什么?
Sem*_*ker 11
作为指定在这里,你可以得到的值作为一个长期的,而不是.
我无法测试它,但你可以试试这个:
PreparedStatement statement = client.session.prepare("select count(*) from corpus.word_usage");
ResultSet results = client.session.execute(statement.bind());
Row row = results.one();
long expected = row.getLong("count");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7235 次 |
| 最近记录: |