Rani
Rani

Reputation: 401

insertion error with cassandra CQL3-Hex Bytes conversion error

when I inert data into table using cassandra -jdbc I got error java.sql.SQLSyntaxErrorException: cannot parse 'ani' as hex bytes

Connected to Test Cluster at localhost:9160. [cqlsh 2.3.0 | Cassandra 1.2.0 | CQL spec 3.0.0 | Thrift protocol 19.35.0] USING CQL3 create table

cqlsh:testkeyspace> create columnfamily login(
                ... key varchar primary key,
                ... name varchar,
                ... password varchar);


package com.bsmart;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class InsertCass {

        public static void main(String[] args) {
            try
            {
                Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
                Connection con =DriverManager.getConnection("jdbc:cassandra://localhost:9160/testkeyspace");

                String qry = "INSERT INTO login (KEY, name, password) VALUES ( 't', 'ani','agrawal');";
                PreparedStatement smt = con.prepareStatement(qry);
                smt.execute();
                // int i=smt.executeUpdate();

                System.out.println("records inserted>>>>");



            }
            catch(Exception e)
            {
                System.out.println(" error: "+e.getMessage());
                e.printStackTrace();
            }

    }

but ERROR-

log4j:WARN No appenders could be found for logger (org.apache.cassandra.cql.jdbc.CassandraDriver).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.sql.SQLSyntaxErrorException: cannot parse 'ani' as hex bytes
    at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.doExecute(CassandraPreparedStatement.java:155)
    at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.execute(CassandraPreparedStatement.java:191)
    at com.bsmart.InsertCass.main(InsertCass.java:18)
 error: cannot parse 'ani' as hex bytes

please help me. Thanks

Upvotes: 4

Views: 849

Answers (2)

Highstead
Highstead

Reputation: 2441

Had this problem myself but in my case it was from a type of double.

In the case of python make sure to specify the appropriate version of cql

cql.connect(cluster_address, port, keyspace, cql_version='3.1.1')

Upvotes: 0

jbellis
jbellis

Reputation: 19377

You need to create the name column as text or varchar. The error you are getting suggests that it was created as blob.

Upvotes: 1

Related Questions