Eclipseで、javaでcassandraにアクセスする環境を構築しています。
以下サイトを参考にしています。
https://gihyo.jp/dev/serial/01/cassandra/0004?page=3
簡単なインサートで、サンプルプログラムを動かすと以下のようなエラーが発生しています。
###発生している問題・エラーメッセージ
型 Cassandra.Client のメソッド insert(ByteBuffer, ColumnParent, Column, ConsistencyLevel) は 引数 (String, String, ColumnPath, byte[], long, ConsistencyLevel) に適用できません
どう修正、対応すればいいのでしょうか?
eclipse、java、cassandraどれも最近学習を進めながら取り組んでいるため、どこでつまづいているかもわからず稚拙な質問かもしれませんが、ご教授いただけないでしょうか。
以下のバージョンで作っています。
Eclipse:Version: 2018-09 (4.9.0)
cassandra:apache-cassandra-3.11.3 6をダウンロードしてインストール
jdk1.8.0_181.jdk使用
試しているプログラムは以下になります。
package examples; import org.apache.cassandra.thrift.Cassandra; import org.apache.cassandra.thrift.ColumnPath; import org.apache.cassandra.thrift.ConsistencyLevel; import org.apache.cassandra.thrift.InvalidRequestException; import org.apache.cassandra.thrift.TimedOutException; import org.apache.cassandra.thrift.UnavailableException; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransportException; /** * シンプルなインサート。 * */ public class SimpleInsert { public static final String KEYSPACE = "Keyspace1"; public static final String COLUMN_FAMILY = "Standard1"; public static void main(String[] args) { TSocket transport = new TSocket("localhost", 9160); TProtocol protocol = new TBinaryProtocol(transport); try { transport.open(); } catch (TTransportException e) { throw new RuntimeException(e); } Cassandra.Client client = new Cassandra.Client(protocol); try { final String key = "sample1"; final String columnName = "hoge"; final String value = "sample_value"; final long timestamp = System.currentTimeMillis(); // ColumnPathは単一のカラムの位置を特定するためのクラス final ColumnPath columnPath = new ColumnPath(COLUMN_FAMILY); columnPath.setColumn(columnName.getBytes()); // 1件カラムをインサート client.insert(KEYSPACE, key, columnPath, value.getBytes(), timestamp, ConsistencyLevel.ONE); } catch (InvalidRequestException e) { throw new RuntimeException(e); } catch (UnavailableException e) { throw new RuntimeException(e); } catch (TimedOutException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } finally { try { transport.flush(); } catch (TTransportException e) { throw new RuntimeException(e); } finally { transport.close(); } } System.out.println("1件インサート完了."); } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。