2014-01-30 62 views
1

在我的示例應用程序中,以下代碼段工作正常。CQL SELECT失敗並顯示prepareStatement

SELECT_CQL = "SELECT * FROM " + STREAM_NAME_IN_CASSANDRA + " WHERE '" + CONTEXT_ID_COLUMN + "'=?"; 
Connection connection = getConnection(); 
statement = connection.prepareStatement(SELECT_CQL); 
statement.setString(1, "123"); 
resultSet = statement.executeQuery(); 

但是,當我嘗試添加另一個參數的where子句查詢返回什麼都沒有!

SELECT_CQL = "SELECT * FROM " + STREAM_NAME_IN_CASSANDRA + " WHERE '" + CONTEXT_ID_COLUMN + "'=? AND '"+TIMESTAMP_COLUMN+"'=?"; 
Connection connection = getConnection(); 
statement = connection.prepareStatement(SELECT_CQL); 
statement.setString(1, "123"); 
statement.setString(2, "1390996577514"); 
resultSet = statement.executeQuery(); 

當我嘗試在cqlsh終端內的確切查詢,它工作正常。

+0

bigint,謝謝你指出這個..解決我的問題,通過使用,statement.setLong(2,1390996577514L); – udarakr

回答

1
statement.setString(2, "1390996577514"); 

仔細檢查您的TIMESTAMP_COLUMN的數據類型並確保它是一個字符串。否則,您需要使用適當的「設置」方法。例如:

statement.setLong(2, 1390996577514L); 
相關問題