Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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');"; // 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)
like image 266
Reusable Avatar asked Feb 23 '23 05:02

Reusable


1 Answers

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');";
like image 51
Theodore Hong Avatar answered Apr 07 '23 09:04

Theodore Hong