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)
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');";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.