java Cassandra CQL 无法插入(输入时没有可行的替代方案)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7118619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cassandra CQL unable to insert (no viable alternative at input)
提问by Reusable
After setup cassandra (0.8.4) and tested with insert and select via CLI, i move on to JDBC (1.0.3) with CQL.
在设置 cassandra (0.8.4) 并通过 CLI 进行插入和选择测试后,我继续使用 CQL 进行 JDBC (1.0.3)。
This is where, i encounter SQLException on following code, any idea?
这就是我在以下代码中遇到 SQLException 的地方,知道吗?
Connection conn = DriverManager.getConnection(url);
String sql = "INSERT INTO row (KEY, first, last, age) VALUES ( 'Jones', 'Jones', 'Lang', '32');"; // internal error
Statement stmt = conn.createStatement();
stmt.execute(sql);
The exception:
例外:
java.sql.SQLException: line 1:22 no viable alternative at input 'first'
at org.apache.cassandra.cql.jdbc.CassandraStatement.execute(CassandraStatement.java:160)
at Cassandra.Insert.main(Insert.java:22)
回答by Theodore Hong
first
is a CQL keyword, you need to put it in quotes. Try:
first
是一个 CQL 关键字,你需要把它放在引号中。尝试:
String sql = "INSERT INTO row ('KEY', 'first', 'last', 'age') VALUES ( 'Jones', 'Jones', 'Lang', '32');";