加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

nosql – cassandra插入错误CQL3-Hex字节转换错误

发布时间:2020-12-13 13:28:00 所属栏目:百科 来源:网络整理
导读:当我使用cassandra -jdbc将数据惰性化到表中时我得到错误 java.sql.SQLSyntaxErrorException:无法将’ani’解析为十六进制字节 在localhost:9160连接到测试群集. [cqlsh 2.3.0 | Cassandra 1.2.0 | CQL规范3.0.0 |节俭协议19.35.0] 使用CQL3创建表 cqlsh:t
当我使用cassandra -jdbc将数据惰性化到表中时我得到错误 java.sql.SQLSyntaxErrorException:无法将’ani’解析为十六进制字节

在localhost:9160连接到测试群集.
[cqlsh 2.3.0 | Cassandra 1.2.0 | CQL规范3.0.0 |节俭协议19.35.0]
使用CQL3创建表

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();
            }

    }

但是错误 –

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

请帮我.
谢谢

解决方法

您需要将name列创建为text或varchar.您收到的错误表明它是作为blob创建的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读