how to read file from cassandra and write file to cassandra?
从上面的链接,我找到了用Cassandra读写文件的方法,但我不知道表格的结构。
下面的代码是将文件插入Cassandra的方法。我猜filename
和file
是两列(它是“文件名”主键吗?)。我们写file
时CREATE TABLE (...,...,...)
的类型是什么。“blob”好吗?
ByteBuffer fileByteBuffer = ByteBuffer.wrap( readFileToByteArray( filename ) );
Statement insertFile = QueryBuilder.insertInto( "files" ).value( "filename", filename ).value( "file", fileByteBuffer );
session.execute( insertFile );
我创建了columnfamily:
"CREATE TABLE " + columnfamily + " ("
+ PK+ " varchar PRIMARY KEY,"
+ " password varchar ,"
+ " file blob"
+ ");";
我查询:
Statement insertFile = QueryBuilder.insertInto(keyspace + "."+columnfamily)
.value(PK, "LDCR.lua").value("file", fileByteBuffer).value("password", "654321");
session.execute(insertFile);
但它说:
com.datastax.driver.core.exceptions.InvalidQueryException:unconfigured columnfamily