开发者

Cassandra CQL unable to insert (no viable alternative at input)

开发者 https://www.devze.com 2023-03-29 00:09 出处:网络
After setup cassandra (0.8.4) and tested with insert and select via CLI, i move on to JDBC (1.0.3) with CQL.

After setup cassandra (0.8.4) and tested with insert and select via CLI, i move on to JDBC (1.0.3) with CQL.

This is where, i encounter SQLException on following code, any idea?

Connection conn =  DriverManager.getConnection(url);             

String sql = "INSERT INTO row (KEY, first, last, age) VALUES ( 'Jones', 'Jones', 'Lang', '32');"; // interna开发者_Python百科l 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)


first is a CQL keyword, you need to put it in quotes. Try:

String sql = "INSERT INTO row ('KEY', 'first', 'last', 'age') VALUES ( 'Jones', 'Jones', 'Lang', '32');";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号