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

21,134

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');";
Share:
21,134
Reusable
Author by

Reusable

Updated on July 09, 2022

Comments

  • Reusable
    Reusable almost 2 years

    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)
    
  • FelikZ
    FelikZ almost 11 years
    Tryed those in CQL console, but it doesn't work for me: cqlsh:testfamily> INSERT INTO tags ('KEY', 'first', 'last', 'age') VALUES ( 'Jones', 'Jones', 'Lang', '32'); Bad Request: line 1:42 no viable alternative at input 'age'
  • BushMinusZero
    BushMinusZero over 9 years
    This error refers to a parsing problem. The real underlying issue is that it is expecting an integer for 'age' but you are passing it a string.