我已經和Cassandra合作過很多年了,覺得我多年來已經忍受了來自數據庫的足夠的BS。只是想知道爲什麼這不適用於DataStore Java驅動程序的Apache Cassandra 2.1.0(或2.0.8)w/2.1.1。這真的好像應該工作。卡桑德拉是壞了還是我犯了一個大錯誤?
public class BS {
public static void main(String [] args) {
Cluster cluster = Cluster.builder().addContactPoint("192.168.1.6").build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
Session session = cluster.connect();
session.execute("CREATE KEYSPACE IF NOT EXISTS fook WITH replication= {'class':'SimpleStrategy', 'replication_factor':1 }");
session.execute("CREATE TABLE IF NOT EXISTS fook.dooftbl (id bigint PRIMARY KEY, doof text, ownerid bigint)");
long id = new Random().nextLong();
long ownerid = new Random().nextLong();
String doof = "broken db";
String load = "INSERT INTO fook.dooftbl (id,doof,ownerid) VALUES (?,?,?)";
PreparedStatement ps = session.prepare(load);
session.execute(ps.bind(id,doof,ownerid));
try {
String cql = "SELECT doof FROM fook.dooftbl WHERE id=?";
PreparedStatement ps2 = session.prepare(cql);
ResultSet rs= session.execute(ps2.bind(id));
System.out.println("Result set: " + rs.toString() + " size: " + rs.all().size() + " fullyFetched:" + rs.isFullyFetched());
//Row one = rs.one();
//if (one!=null)
// System.out.println("It worked. You will never have to worry about seeing this msg.");
String msg = null;
for (Row r : rs.all()) {
msg = r.getString("doof");
}
System.out.println("msg:" + msg);
}
catch (Exception e) {
e.printStackTrace();
}
cluster.close();
}
}
我在這裏做錯了什麼,還是比較小的東西?
輸出:
連到羣集:測試羣集
結果集:結果集[耗盡:假,列[笨蛋(VARCHAR)]]尺寸:1 fullyFetched:真
MSG :空
請描述_isn't working_。你期望它做什麼,爲什麼?它做什麼呢? – 2014-09-20 14:19:42
最低限度,我希望它能顯示「It worked ...」字符串。相反,它沒有顯示它。 – 2014-09-20 14:25:37
@AlexWhite它顯示了什麼_does_?至少連接到集羣? – 2014-09-20 14:57:13